sort the list
Shi Mu
samrobertsmith at gmail.com
Mon Nov 21 07:12:26 EST 2005
On 11/21/05, Daniel Schüle <uval at rz.uni-karlsruhe.de> wrote:
> Shi Mu wrote:
> > I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list
> > based on the second value in the item?
> > That is,
> > I want the list to be:
> > [[3,2],[1,4],[2,5],[3,9]]
>
>
> >>> lst = [[1,4],[3,9],[2,5],[3,2]]
> >>> lst
> [[1, 4], [3, 9], [2, 5], [3, 2]]
> >>>
> >>>
> >>> lst.sort(cmp = lambda x,y: cmp(x[1], y[1]))
> >>> lst
> [[3, 2], [1, 4], [2, 5], [3, 9]]
> >>>
>
> works for Python 2.4
> in earlier Pythons just let cmp = .. away
>
> Regards, Daniel
what does let cmp = .. away mean?
More information about the Python-list
mailing list