Very concise == neat solutions. Yummy. ;-) Thanks for your replies!

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Wed, 1/13/10, Sander Sweers <[email protected]> wrote:


From: Sander Sweers <[email protected]>
Subject: Re: [Tutor] samples on sort method of sequence object.
To: "Albert-Jan Roskam" <[email protected]>
Cc: "*tutor python" <[email protected]>
Date: Wednesday, January 13, 2010, 2:14 PM


2010/1/13 Albert-Jan Roskam <[email protected]>
>
> Interesting. Can this also be used to make sorting of alphanumerical list 
> items in a 'numerical' way easier?
> >>> x
> ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', 
> 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12']

Yes.
>>> x
['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5',
'var_6', 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10',
'var_12']
>>> sorted(x, key=lamda x: int(x.strip('var_')))
SyntaxError: invalid syntax
>>> sorted(x, key=lambda x: int(x.strip('var_')))
['var_0', 'var_1', 'var_2', 'var_3', 'var_4', 'var_5', 'var_6',
'var_7', 'var_8', 'var_9', 'var_10', 'var_11', 'var_12', 'var_13',
'var_14']

Greets
Sander



      
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to