Sorting a multidimensional array by multiple keys

Steven Bethard steven.bethard at
Mon Apr 2 16:06:47 CEST 2007

Thomas Krüger wrote:
> Alex Martelli schrieb:
>> Thomas Krüger <newsgroups at> wrote:
>>> def sorter(a, b):
>>>     return cmp(,
>>> obj_lst.sort(sorter)
>> A MUCH better way to obtain exactly the same semantics would be:
>> def getid(a):
>>     return
>> obj_list.sort(key=getid)
> Frankly speaking the purpose of the example was to show how to pass a
> function as argument for the sort method.
> Your code may be more efficient but it explains something different.

Yes, but there's almost never a reason to use the cmp= argument to 
sort() anymore.  It's almost always better to use the key= argument.


More information about the Python-list mailing list