Why keep identity-based equality comparison?

Antoon Pardon apardon at forel.vub.ac.be
Thu Jan 12 05:43:18 EST 2006

Op 2006-01-12, Paul Rubin schreef <http>:
> Antoon Pardon <apardon at forel.vub.ac.be> writes:
>> There is a use case for things like 1 < (1,3) making sense and denoting
>> a total order. When you have a hetergenous list, having a total order
>> makes it possible to sort the list which will make it easier to
>> weed out duplicates. So why don't you demand a use case for the
>> new behaviour to counter this use case?
> This could easily be handled with an alternate comparison function
> that you pass to the sort function.

Yes that is true and will be all that is needed in most cases.
But in the case where new items are regularly added, one might
prefer to use the bisect module for something like this. The
bisect module doesn't have an alternate comparison function
neither has the heapqueue module.

O.K. lets try to get at this from a more constructive direction.
Python will get the behaviour that 1 < (1,3) will throw an exception.
What can python do to help for cases like the above.

1) Python could provide a seperare total ordering, maybe with operators
   like '<|' and '|>' and function operator.rank (with functionlity
   similar to cmp)

2) Python could make it possible to associate a ranking with a
   container. This ranking is used by default by methods and
   modules like sort, bisect and heapqueue.

3) Python could provide the possibility of providing an alternate
   comparison function with heapqueue, bisect and similar modules.

These options are not meant to be exclusive. But if a choice is
to be made I would prefer (2) (a little) over (1) over (3).

Antoon Pardon

More information about the Python-list mailing list