[Python-Dev] Keep default comparisons - or add a second set?

Paul Moore p.f.moore at gmail.com
Mon Dec 19 21:19:58 CET 2005


On 12/19/05, Jim Jewett <jimjjewett at gmail.com> wrote:

> Unfortunately, one very common use case of comparisons is to get a
> canonical order.  If the order is sensible, all the better, but that
> is not strictly required.  One of Python's selling points (especially
> compared to Java) is that getting a canonical order "just works", even
> if the objects being sorted are not carefully homogenized by hand.
> Python itself relies on this when comparing same-length dictionaries.

While I agree that this is a useful property, and I'd like it to be
true, it isn't even today:

>>> import Numeric
>>> a = Numeric.array((1,2,3))
>>> a
array([1, 2, 3])
>>> sorted([a, (1,2,3), 1, 2, '123'])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: function not supported for these types, and can't coerce to supported
 types
>>> a < '123'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: function not supported for these types, and can't coerce to supported
 types
>>>

Numeric arrays are the canonical example of an "awkward case" when
discussing comparisons...

OTOH, I'm not sure I want to see more "awkward cases" added.

Paul.


More information about the Python-Dev mailing list