sorting a dictionary
p-abel at t-online.de
Thu Feb 6 23:29:07 CET 2003
Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote in message news:<mailman.1044499694.2723.python-list at python.org>...
> On Wed, 2003-02-05 at 18:24, Erik Max Francis wrote:
> > It's a tip of the hat to the mathematical fact that comparisons between
> > complex numbers is undefined.
> I think this was understood by Peter Abel (who demonstrated a point
> about comparing complex numbers with floats and strings). He ultimately
> had a different point (I am assuming).
> I believe what he found odd was that, this doesn't throw an exception:
> >>> max([41, 'X', (1+2j)])
> whereas this does:
> >>> max([41, (1+2j), 'X'])
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=
> So the order of the list of values can determine whether max()/min()
> will raise a TypeError. <snip>
OK the first thing I wondered about was what you describe above.
But thinking more about this stuff I asked myself why complex
crashes against integer and not against char.
But searching an answer to this questions and also after reading
the following posts and remembering Alex Martelli who taught me
something about lexical order in an other thread I found some
explanatiions for myself.
1. As you already explained comparing int and complex makes no
sense from the mathematical point of view. Int is a scalar
and complex is something like a vector with length and direction.
So which property should be compared.
2. Comparing complex and char is not quite clear at the first view.
But comparing it lexically - I think - can make sense.
The same way int or float and char does.
If it is as simple as I described above, I have no problems with
More information about the Python-list