Re: Pythonic list reordering

2010-04-10 Thread alex23
MRAB 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-10 Thread MRAB
alex23 wrote: On Apr 9, 8:52 am, 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? This approach doesn't rely on knowing th

Re: Pythonic list reordering

2010-04-10 Thread alex23
On Apr 9, 8:52 am, 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? This approach doesn't rely on knowing the format

Re: Pythonic list reordering

2010-04-10 Thread Kent Engström
Ben Racine 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 miscellaneous string

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

Re: Pythonic list reordering

2010-04-09 Thread Joaquin Abian
On Apr 9, 1:58 am, Chris Rebert wrote: > On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian wrote: > > On Apr 9, 12:52 am, 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 num

Re: Pythonic list reordering

2010-04-08 Thread Chris Rebert
On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian wrote: > On Apr 9, 12:52 am, 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 eleg

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 s

Re: Pythonic list reordering

2010-04-08 Thread Joaquin Abian
On Apr 9, 12:52 am, 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. not sure about elega

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: int

Re: Pythonic list reordering

2010-04-08 Thread Chris Rebert
On Thu, Apr 8, 2010 at 3:52 PM, 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. a = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', 'dir_330_error.