How to sort this kind of list easily?
ben at benlast.com
Fri Aug 20 13:14:11 CEST 2004
> From: Anthony Baxter, in response to BruceKL WhoH
> list.sort sorts tuples by first argument, then second &c. If you want a
> custom sort order, look at the decorate-sort-undecorate pattern.
Or if you want to sort only on your Id, use a lambda:
l.sort(lambda x,y: cmp(x,y))
To force sorting on just the nth element of the tuples, replace 0 with n in
More information about the Python-list