[Python-3000] Please re-add __cmp__ to python 3000
Guido van Rossum
guido at python.org
Thu Oct 18 01:00:23 CEST 2007
On 10/17/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> I'm having troubles coming up with things where the *basic* operator
> is really a cmp-like function.
Here's one. When implementing the '<' operator on lists or tuples, you
really want to call the 'cmp' operator on the individual items,
because otherwise (if all you have is == and <) the algorithm becomes
something like "compare for equality until you've found the first pair
of items that are unequal; then compare those items again using < to
decide the final outcome". If you don't believe this, try to implement
this operation using only == or < without comparing any two items more
than once.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list