Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:06:17+00:00 2026-05-25T19:06:17+00:00

short of renaming/fixing the logging module on the webservers… when i do a list.sort(),

  • 0

short of renaming/fixing the logging module on the webservers… when i do a list.sort(), the list entries get placed in the following order:

2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.0.gz
2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.1.gz
2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.2.gz
2011-09-21 19:15:54,732 DEBUG __main__ 44: running www.site.com-110731.log.3.gz
2011-09-21 19:15:54,732 DEBUG __main__ 44: running www.site.com-110731.log.gz

how would i sort a list, to get (ie the entry eithout a digit to be first):

2011-09-21 19:15:54,732 DEBUG __main__ 44: running www.site.com-110731.log.gz
2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.0.gz
2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.1.gz
2011-09-21 19:15:54,731 DEBUG __main__ 44: running www.site.com-110731.log.2.gz
2011-09-21 19:15:54,732 DEBUG __main__ 44: running www.site.com-110731.log.3.gz

THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:06:18+00:00Added an answer on May 25, 2026 at 7:06 pm

    You would probably want to write a custom comparator to pass to sort; in fact, you probably need to anyway, because you’re likely getting a lexicographical sort order instead of the intended (I presume) numerical order.

    For instance, if you know that the filenames will only differ in those digits, you’d write a comparator that extracts those digits, converts them to int, and then compares based on that value.

    Taking your examples as canonical, your comparator might look something like this:

    import re
    def extract(s):
        r = re.compile(r'\.(\d+)\.log\.((\d*)\.)?gz')
        m = r.search(s)
        file = int(m.group(1))
        if not m.group(2):
            return (file, -1)
        index = int(m.group(3))
        return (file, index)
    
    def comparator(s1, s2): return cmp(extract(s1), extract(s2))
    

    This prefers to sort based on the “file” number (the first one), and then by the “index” number (the second one). Note that it takes advantage of the fact that using cmp on tuples works as we require.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short of cutting and pasting, is there a way to sort the methods in
Short of renaming the constructor parameter in the primary constructor of class B ,
puts Renaming files... folder_path = /home/papuccino1/Desktop/Test files = Dir.glob(folder_path + /*).sort extension = File.extname(files[0])
Here's my .rb file: puts Renaming files... folder_path = /home/papuccino1/Desktop/Test Dir.glob(folder_path + /*).sort.each do
Short and sweet: Why does the following block of Objective-C code not produce a
Short version: How do I create the <> column manually? Long version: In Access
Short story: my footer doesn't react to margin-top, i've tried many various way (well
Short My tables structure looks like that And here is Sql statements $stmt =
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.