Sorting Multidimesional array(newbie)

Peter Otten __peter__ at web.de
Thu Dec 14 03:13:48 EST 2006


Brian Mills wrote:

>> but using a compare function instead of a key mapper is not good advice,
>> in general.  brief discussion here:
>>
http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python

> Is this mostly because of the stability problem described here:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ?  Or is
> it more a performance issue due having to make so many function calls?

http://docs.python.org/lib/typesseq-mutable.html

"""Starting with Python 2.3, the sort() method is guaranteed to be
stable."""

So performance it is. It is also often simpler once you get used to it and
start seeing the pattern

def mycmp(a, b):
   return cmp(mykey(a), mykey(b))

in many of your custom comparison functions.

Peter




More information about the Python-list mailing list