[Python-Dev] decorate-sort-undecorate
Geoffrey Talvola
gtalvola at nameconnector.com
Tue Oct 14 16:25:17 EDT 2003
Tim Peters wrote:
> The
> cases where DSU
> gets used are the ones where the object isn't the key (so
> that stability or
> lack thereof becomes obvious), and where the user cares about
> speed (else
> they'd just pass a custom comparison function instead of
> bothering with
> DSU).
I disagree... I almost always use DSU in any circumstances because I find it
easier and more natural to write:
def keyfunc(record):
return record.LastName.lower(), record.FirstName.lower(),
record.PhoneNumber
mylist = sortUsingKeyFunc(mylist, keyfunc)
than to have to write an equivalent comparison function:
def cmpfunc(r1, r2):
return cmp((r1.LastName.lower(), r1.FirstName.lower(), r1.PhoneNumber),
(r2.LastName.lower(), r2.FirstName.lower(), r2.PhoneNumber))
mylist.sort(cmpfunc)
so for me, ease of use is the reason, not speed. Of course, it doesn't
_hurt_ that DSU is faster...
- Geoff
More information about the Python-Dev
mailing list