sorting a dictionary

Alex Martelli aleax at
Thu Feb 6 01:18:32 CET 2003

Peter Abel wrote:
> But what I do not understand is why the following doesn't crash:
>>>> d={'a': 41, 'b': 'X', 'd': (1+2j)}
>>>> max(d.values())
> 'X'

>>> 2j>'X'
>>> 2j<'X'
>>> 2j>43
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot compare complex numbers using <, <=, >, >=

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...?).


More information about the Python-list mailing list