sorting a dictionary

Alex Martelli aleax at aleax.it
Thu Feb 6 04:31:26 EST 2003


Erik Max Francis wrote:

> Alex Martelli wrote:
> 
>> you CAN compare a complex number to a string -- just not to
>> any other number.  Now, that is a "feature" I'm not going to
>> try to defend (can anybody think of a GOOD reason, as opposed
>> to an implementation detail leaking out...?).
> 
> It's a tip of the hat to the mathematical fact that comparisons between
> complex numbers is undefined.  I agree that in light of Python's

And comparing a complex number with a string IS defined...?

> generality of comparisons, it's a little weird to restrict the case
> where a complex number is being compared to another numeric value, but
> to someone with a mathematics background the reason is obvious.  I've

It's not obvious to me why Python claims that 2j<'1' is defined while 2j<1
is not.  If the '<' indicates an arbitrary total ordering between values, 
as the former would suggest, then there's no obvious reason the ordering
is made non-total, when it's obviously trivial to define orderings
among complex numbers that are just as arbitrary as orderings BETWEEN
complex numbers and strings (e.g., Python 1.5.2 had no problem there).

> never understood why this "feature" generates such discord.

In my case, it's the inconsistency between 2j<'1' working while 2j<1
doesn't -- if both raised (or neither raised, as in 1.5.2), I could
see the sense of it.  I'd prefer the 1.5.2 behavior (so the subtle
distinguos I had to draw in this thread were not needed) but I could
accept "no complex number can EVER be compared with ANYTHING" as
having some use (and no practical downside wrt the alternative of
"complex numbers can be compared with strings but not with numbers").

But the current neither-fish-nor-fowl situation is just silly.


Alex





More information about the Python-list mailing list