Re: Pythonic list reordering

2010-04-10 Thread Kent Engström
Ben Racine i3enha...@gmail.com writes: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? I use code like the hack below to sort

Re: Pythonic list reordering

2010-04-10 Thread alex23
On Apr 9, 8:52 am, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? This approach doesn't rely on

Re: Pythonic list reordering

2010-04-10 Thread MRAB
alex23 wrote: On Apr 9, 8:52 am, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? This approach

Re: Pythonic list reordering

2010-04-10 Thread alex23
MRAB pyt...@mrabarnett.plus.com wrote: The string module still exists in Python 3.x, but the string functions which have been superseded by string methods have been removed. Awesome, thanks for the heads up. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic list reordering

2010-04-09 Thread Joaquin Abian
On Apr 9, 1:58 am, Chris Rebert c...@rebertia.com wrote: On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian gatoyga...@gmail.com wrote: On Apr 9, 12:52 am, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat']

Re: Pythonic list reordering

2010-04-09 Thread Tobiah
How about a one liner? L.sort(key=lambda s: int(s.split('_')[1])) (Which is not necessarily elegant, but it is short.) I grant it a measure of elegance as well. -- http://mail.python.org/mailman/listinfo/python-list

Pythonic list reordering

2010-04-08 Thread Ben Racine
I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic list reordering

2010-04-08 Thread Chris Rebert
On Thu, Apr 8, 2010 at 3:52 PM, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. a = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat',

Re: Pythonic list reordering

2010-04-08 Thread Gary Herron
Ben Racine wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. How about a one liner? L.sort(key=lambda s:

Re: Pythonic list reordering

2010-04-08 Thread Joaquin Abian
On Apr 9, 12:52 am, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. not sure

Re: Pythonic list reordering

2010-04-08 Thread Lie Ryan
On 04/09/10 08:52, Ben Racine wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only. Does someone have an elegant solution to this? Thanks, Ben R. list.sort() and sorted()

Re: Pythonic list reordering

2010-04-08 Thread Chris Rebert
On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian gatoyga...@gmail.com wrote: On Apr 9, 12:52 am, Ben Racine i3enha...@gmail.com wrote: I have a list... ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.dat'] I want to sort it based upon the numerical value only.