Guido rethinking removal of cmp from sort method
Stefan Behnel
stefan_ml at behnel.de
Tue Mar 15 05:01:42 EDT 2011
Paul Rubin, 15.03.2011 09:00:
> Ian Kelly writes:
>> I would think that you can sort them with key as long as none of the
>> sequences are equal (which would result in an infinite loop using
>> either method). Why not this?
>
> Yes you can do something like that, but look how ugly it is compared
> with using cmp.
I would argue that it's a rare use case, though. In most cases, memory
doesn't really matter, and the overhead of a decorated sort is acceptable.
In some cases, where space matters, an external sort is a better choice or
even the only thing that will work, so all that's left are the cases where
speed really needs to be traded for space *and* an external sort is not
applicable, and those where things can be expressed more easily using cmp
than using a key. For the latter, there's support in the standard library,
as Steven pointed out. Now, the question that remains is: are the few
remaining cases worth being supported directly, thus complicating the
internal source code of the Python runtime?
Stefan
More information about the Python-list
mailing list