Guido rethinking removal of cmp from sort method

Dan Stromberg drsalists at gmail.com
Fri Mar 25 19:50:05 EDT 2011


On Sun, Mar 13, 2011 at 5:59 AM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> The removal of cmp from the sort method of lists is probably the most
> disliked change in Python 3. On the python-dev mailing list at the
> moment, Guido is considering whether or not it was a mistake.
>
> If anyone has any use-cases for sorting with a comparison function that
> either can't be written using a key function, or that perform really
> badly when done so, this would be a good time to speak up


The point of increased memory use seems possibly relevant.  I tried to test
for that yesterday using some big lists of tuples of floats, and didn't see
it having much significance (if anything the cmp version seemed to take More
memory), but it might merit further study, as it'll be a while before cell
phones (and refrigerators) have an excess of memory - and I very much want
to run Python on my cell phone (and wouldn't mind it on my fridge).

There's also the issue of a lazy comparison function, that I don't seem to
have gotten a response to - if you have a Very expensive comparison
operation involving megabytes or even gigabytes of data, and want to perform
just enough of it to get the job done, how does one do this with a key
comparator and no cmp comparator?  It seems like you could almost do it by
using a generator for your key comparator, but it also seems like the stuff
in memory would add up really (too) fast.  This program has an example:
http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html#python
(The version at the following URL might be a little newer)
http://stromberg.dnsalias.org/cgi-bin/viewvc.cgi/equivalence-classes/trunk/equivs2-python/?root=svn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110325/a151ca26/attachment.html>


More information about the Python-list mailing list