On Sat, 30 Jul 2005 13:22:47 +0000, Adriano Varoli Piazza wrote: > As far as I recall from Math Analysis, which I studied two months ago, > you can't sort complex numbers. It makes no sense. The reason being > (reading from my book), it's not possible to define an order that > preserves the properties of arithmetical operations on complex numbers. > So you can't order them, and you can't compare them.
You are confusing mathematical ordering with sorting a list. Here, I will sort some mixed complex and real numbers for you. If you look at them closely, you will even be able to work out the algorithm I used to sort them. 1 1+0j 1+7j 2 2+3j 3+3j 3-3j 3+4j 4 4+2j It was easy. I never once asked myself whether some complex number was greater or less than another, I just asked "which one comes first in a lexicographic sort?" The two questions are NOT the same, and it is an ugliness in an otherwise beautiful language that Python treats them as the same. Mathematically, 1 == 1.0 == 1+0j but in the dictionary "1" should sort before "1.0" which sorts before "1.0+0.0j". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list