HELP:sorting list of outline numbers

Felix Collins felix at keyremovethisghost.com
Tue Aug 2 21:59:02 EDT 2005


Robert Kern wrote:
> Felix Collins wrote:
> 
> Use the "key" keyword argument to list.sort().
> 
> In [1]: outline = ['1.12', '1.1', '1', '1.2']
> 
> In [2]: outline.sort(key=lambda x: map(int, x.split('.')))
> 
> In [3]: outline
> Out[3]: ['1', '1.1', '1.2', '1.12']
> 


Is this new in 2.4?  I have to use 2.3 as I'm working with Trac.

Traceback (most recent call last):
   File "<pyshell#21>", line 1, in -toplevel-
     keys.sort(key=lambda x: map(int, x.split('.')))
TypeError: sort() takes no keyword arguments


Thanks Scott and Robert for your quick help.  This list is amazing!

Regards,
Felix



More information about the Python-list mailing list