sorting list of tuples by second (third...) tuple item
justin at iago.org
Fri Feb 15 15:27:42 CET 2002
kp87 at lycos.com (kevin parks) writes:
> How would you sort something based on 2 criteria. Say you have a list
> of lists (i hate tuples). first thing you want is everything sorted by
> the first value and then everything that has the same value for 
> then sorted by 
This is the default behavior of Python's listobject's sort method.
It will sort by the first element, then the second, then the third, etc...
If you want some other order, you have two choices:
- write a custom cmp function to pass to sort
- decorate your list so that the default sort does what you want
More information about the Python-list