# [Tutor] samples on sort method of sequence object.

Albert-Jan Roskam fomcl at yahoo.com
Wed Jan 13 14:32:58 CET 2010

```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 <sander.sweers at gmail.com> wrote:

From: Sander Sweers <sander.sweers at gmail.com>
Subject: Re: [Tutor] samples on sort method of sequence object.
To: "Albert-Jan Roskam" <fomcl at yahoo.com>
Cc: "*tutor python" <tutor at python.org>
Date: Wednesday, January 13, 2010, 2:14 PM

2010/1/13 Albert-Jan Roskam <fomcl at yahoo.com>
>
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100113/51192f00/attachment.htm>
```