Is 0 > None??

Alex Martelli aleax at aleax.it
Fri Aug 31 10:36:23 EDT 2001


"Terry Reedy" <tjreedy at home.com> wrote in message
news:qAMj7.156063$EP6.43986636 at news1.rdc2.pa.home.com...
>
> "Manus Hand" <manushand at home.com> wrote in message
> news:3B8F4B03.EFE5E0ED at home.com...
> > It was in 1.5.1, but it wasn't in 1.5.2 or 2.0 or even (I think)
> 2.1.
>
> Behavior of mixed-typed (non-numeric) comparisons is explicitly
> *undefined*.  Only guarantee is consistency within release (or maybe
> just within running program).  Reason for giving otherwise nonsensical
> answer is so list.sort does not bomb and so heterogenous lists can be
> sorted to 'canonical' form before being tuple-ized for use as dict
> key.

This used to make a lot of sense, but now it all breaks down
if any item in the heterogeneous list is a complex number, so
I doubt it makes much sense any more -- you *can't* "put a
heterogenous list in canonical form" by sorting it unless you're
ABSOLUTELY sure that, whatever else the list may contain, it
*DOESN'T* contain even one complex number.

Not by sorting the list itself, that is -- you need to supply
a comparison-method (that will jump through complicated hoops
if it ever meets a complex number), or just-as-carefully use
the decorate-sort-undecorate idiom in a way that *ENSURES*
a complex number is NEVER, EVER compared (with cmp, <, >, &c)
with anything.  Comparing a blue camel to a rocking horse is
fine -- comparing it to a complex number isn't.

I think we could count this among Python's relatively-new
warts, actually:-).


Alex






More information about the Python-list mailing list