Sorting a multidimensional array by multiple keys

Duncan Booth duncan.booth at invalid.invalid
Sat Mar 31 21:57:10 CEST 2007


Peter Otten <__peter__ at web.de> wrote:

> Duncan Booth wrote:
> 
>>>>> from operator import itemgetter
>>>>> data.sort(key=itemgetter(0))
>>>>> data.sort(key=itemgetter(1))
>>>>> data.sort(key=itemgetter(4))
>>>>> data.sort(key=itemgetter(3))
> 
> Or, in Python 2.5:
> 
>>>> data.sort(key=itemgetter(3, 4, 1, 0))
> 
Thanks, I'd forgotten itemgetter had that strangley assymmetric behaviour 
of returning either a single value or a tuple.



More information about the Python-list mailing list