python sorting 2dim. array ?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Sep 25 06:23:35 EDT 2008


fred... at fulladsl.be:
> list[rowindex][colomindex]
> I want to sort on the second colom as first (and as
> second sortfield the first colom).

A good way, in Python 2.5:

>>> from operator import itemgetter
>>> a = [[1, 2], [3, 1], [2, 5], [7, 1]]
>>> a.sort(key=itemgetter(1, 0))
>>> a
[[3, 1], [7, 1], [1, 2], [2, 5]]

Bye,
bearophile



More information about the Python-list mailing list