[Python-Dev] decorate-sort-undecorate

Neil Schemenauer nas-python at python.ca
Tue Oct 14 13:26:27 EDT 2003


On Tue, Oct 14, 2003 at 09:55:54AM -0700, Guido van Rossum wrote:
> If we're going to do a custom object, it should be a fixed-length
> struct containing (1) the key, (2) a C int of sufficient size to hold
> the record index; (3) a pointer to the record, and its comparison
> should only use (1) and (2).

I just thought of another reason why this is a good idea.  Imagine I
want to sort a list of objects that cannot be compared (e.g. complex
numbers).  I would expect

    cnums.sort(key = lambda n: n.real)

to work, not fail with an exception.

  Neil



More information about the Python-Dev mailing list