Help sorting a list by file extension

Cyril Bazin cyril.bazin at gmail.com
Fri Aug 12 13:35:13 CEST 2005


Maybe simpler but not very much simpler: one line for each solution. 

And in your solution the lambda is evaluated at each comparaison of the sort 
algorithm isn't it? 

So your code seems less productive than the bengt's code which apply the 
same code as the lambda only one time by entry in the list.

Cyril

On 8/12/05, George Yoshida <ml at dynkin.com> wrote:
> 
> Bengt Richter wrote:
> >>>>[name for dec,name in sorted((int(nm.split('.')[1]),nm) for nm in 
> namelist)]
> >
> > ['test.1', 'test.2', 'test.3', 'test.4', 'test.10', 'test.15', 'test.20
> ']
> 
> Giving a key argument to sorted will make it simpler::
> 
> >>> sorted(namelist, key=lambda x:int(x.rsplit('.')[-1]))
> 
> -- george
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050812/c16fa4d8/attachment.html>


More information about the Python-list mailing list