A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/038732.html below:

[Python-Dev] decorate-sort-undecorate

[Python-Dev] decorate-sort-undecorateGeoffrey 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4