Comparison of functions

Adriano Varoli Piazza moranar at alice.it
Sat Jul 30 12:43:00 EDT 2005


Steven D'Aprano ha scritto:
> 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". 
> 

If you want to treat numbers as strings, why not convert them before 
sorting them? Python is just saying "He's trying to sort complex 
numbers. No can do". You're trying to make it guess that you want them 
sorted as strings, not as numbers. I don't see how Python treats things 
the same way. I see that real numbers and strings can be compared and 
sorted (asciibetically? don't remember). It has nothing to do with 
complex numbers. The abstraction or overloading or what it is fails, 
because they don't have an order as numbers, and Py is not intelligent 
enough to know that you want them asciibetized

-- 
Adriano Varoli Piazza
The Inside Out: http://moranar.com.ar
MSN: adrianomd at hotmail.com
ICQ: 4410132



More information about the Python-list mailing list