Re: [Tutor] Logical Sorting [Off-Topic]
Or use 'ls -v'. (I said it's off topic on the subject, sorry! It might escaped you, but 'ls' _does_ have a proper sort by version.) Which OS? Most of them, its the GNU version of ls... works on cygwin, linux, bsd, solaris Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
Or use ‘ls -v’. (I said it's “off topic” on the subject, sorry! It might escaped you, but ‘ls’ _does_ have a proper sort by version.) But very interesting, I'd never seen that feature of 'ls' before and the man pages don't say much about it, you need to go to the info pages. But it does indeed look like it would do the job here. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
زياد بن عبدالعزيز الباتلي wrote: [...] Or use ‘ls -v’. (I said it's “off topic” on the subject, sorry! It might escaped you, but ‘ls’ _does_ have a proper sort by version.) Which OS? ~$ uname -mrs FreeBSD 6.1-STABLE i386 ~$ ls -v ls: illegal option -- v usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1] [file ...] 'The Open Group Base Specifications' does not list '-v' either. Norbert -- Warning at the Gates of Bill: Abandon hope, all ye who press ENTER here... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
Ubuntu Linux does: [EMAIL PROTECTED]:~$ ls -v Desktop GDM-DarkGno.tar.gz foktopicstart test.py~ Examples Muziek foktopicstart~ [EMAIL PROTECTED]:~$Here's a copy of a complete ls http://www.mediacollege.com/cgi-bin/man/page.cgi?topic=lsOn my system it's also included in both the man (man ls) and the info (info ls) page ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
Norbert Kaufmann schreef: زياد بن عبدالعزيز الباتلي wrote: [...] Or use ‘ls -v’. (I said it's “off topic” on the subject, sorry! It might escaped you, but ‘ls’ _does_ have a proper sort by version.) Which OS? The one from GNU. It's commonly in GNU/Linux distributions, but it's possible to install on many other OS's too. Many GNU versions of all kinds of tools have extra options and features (for better or for worse, I'm not the one to judge). $ ls --version ls (coreutils) 5.2.1 Written by Richard Stallman and David MacKenzie. Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ ls 100 20 4 $ ls -v 4 20 100 -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
On Sat, 2006-07-08 at 14:39 +0200, Norbert Kaufmann wrote: زياد بن عبدالعزيز الباتلي wrote: [...] Or use ‘ls -v’. (I said it's “off topic” on the subject, sorry! It might escaped you, but ‘ls’ _does_ have a proper sort by version.) Which OS? ~$ uname -mrs FreeBSD 6.1-STABLE i386 ~$ ls -v ls: illegal option -- v usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1] [file ...] 'The Open Group Base Specifications' does not list '-v' either. Norbert Almost all Linux flavours a used have that. I'm currently using “Ubuntu 5.10”. Here's the output of “ls --version”: zamb ~ $ ls --version ls (coreutils) 5.2.1 Written by Richard Stallman and David MacKenzie. Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Logical Sorting
Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. I wrote some code that gets a list like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] When I sort the list, I want it to go from oldest (lowest version) to newest, so the sorted list should look like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] The problem is that since the built in string comparisons compare character by character, so the sort puts 2.6.16 before 2.6.9, and -r11 before -r7. This is obviously not what I want. My question is: are there any modules or built in methods that will do a logical sort on a list like this, and sort it the way I want, or will I have to write my own sorting function? -- Evan Klitzke P.S. I know that the simplest way is just to use ls to sort by time, but it is not necessarily true that older kernel versions have an older time stamp :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting
On 7/7/06, Evan Klitzke [EMAIL PROTECTED] wrote: Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. Err, this is under /usr/src... not that it is really pertinent to my question. -- Evan Klitzke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting
Evan Klitzke wrote: Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. I wrote some code that gets a list like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] When I sort the list, I want it to go from oldest (lowest version) to newest, so the sorted list should look like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] The problem is that since the built in string comparisons compare character by character, so the sort puts 2.6.16 before 2.6.9, and -r11 before -r7. This is obviously not what I want. My question is: are there any modules or built in methods that will do a logical sort on a list like this, and sort it the way I want, or will I have to write my own sorting function? You don't have to write your own sorting function. You do have to write a function that extracts a key from a data item that will sort in the order you want. Here is a version that uses a regular expression to extract the four fields from the data, converts the numbers to integers, and returns a tuple of values that sorts correctly. It works with the data you show but it probably needs tweaks to be more robust, for example it will fail if the version is not three numbers or if the -rxx is missing. In [1]: data = ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] In [2]: import re In [3]: def makeKey(entry): ...: m=re.search(r'-(\d+)\.(\d+)\.(\d+)-[^-]+-r(\d+)', entry) ...: if not m: return entry ...: return map(int, m.group(1, 2, 3, 4)) ...: In [4]: data.sort(key=makeKey) In [5]: data Out[5]: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting
On Fri, 2006-07-07 at 10:09 -0700, Evan Klitzke wrote: Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. I wrote some code that gets a list like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] When I sort the list, I want it to go from oldest (lowest version) to newest, so the sorted list should look like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] The problem is that since the built in string comparisons compare character by character, so the sort puts 2.6.16 before 2.6.9, and -r11 before -r7. This is obviously not what I want. My question is: are there any modules or built in methods that will do a logical sort on a list like this, and sort it the way I want, or will I have to write my own sorting function? There is an rpm-python package that probably includes much of what you want. I have it installed, but never used it. It appears to be pretty light on documentation. I expect it is a python wrapper to a C library. You may find it easier to simply pick apart your data and sort the numbers numerically than wrestle with learning this package unless you have other RPM related tasks. -- Evan Klitzke P.S. I know that the simplest way is just to use ls to sort by time, but it is not necessarily true that older kernel versions have an older time stamp :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting
I did a Google search for python numeric sort and found http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/135435 It seems to do what you want. Marc --- Evan Klitzke [EMAIL PROTECTED] wrote: Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. I wrote some code that gets a list like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] When I sort the list, I want it to go from oldest (lowest version) to newest, so the sorted list should look like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] The problem is that since the built in string comparisons compare character by character, so the sort puts 2.6.16 before 2.6.9, and -r11 before -r7. This is obviously not what I want. My question is: are there any modules or built in methods that will do a logical sort on a list like this, and sort it the way I want, or will I have to write my own sorting function? -- Evan Klitzke P.S. I know that the simplest way is just to use ls to sort by time, but it is not necessarily true that older kernel versions have an older time stamp :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
On Fri, 2006-07-07 at 10:09 -0700, Evan Klitzke wrote: Hi, I am trying to sort a list of directories that correspond to kernel sources under /usr/src/linux. I wrote some code that gets a list like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r11/', 'linux-2.6.16-gentoo-r7/'] When I sort the list, I want it to go from oldest (lowest version) to newest, so the sorted list should look like this: ['linux-2.6.9-gentoo-r4', 'linux-2.6.16-gentoo-r7/', 'linux-2.6.16-gentoo-r11/'] The problem is that since the built in string comparisons compare character by character, so the sort puts 2.6.16 before 2.6.9, and -r11 before -r7. This is obviously not what I want. My question is: are there any modules or built in methods that will do a logical sort on a list like this, and sort it the way I want, or will I have to write my own sorting function? -- Evan Klitzke P.S. I know that the simplest way is just to use ls to sort by time, but it is not necessarily true that older kernel versions have an older time stamp :-) Or use ‘ls -v’. (I said it's “off topic” on the subject, sorry! It might escaped you, but ‘ls’ _does_ have a proper sort by version.) Ziyad. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor