# Comparison of functions

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Jul 30 18:43:22 CEST 2005

```On Sat, 30 Jul 2005 15:32:45 +0200, Reinhold Birkenfeld wrote:

>> Um, I didn't ask to compare complex numbers using comparison operators. I
>> asked to sort a list. And please don't tell me that that sorting is
>> implemented with comparison operators. That just means that the
>> implementation is confusing numeric ordering with sort order.
>
> Sorting is implemented with comparison operators. How should it be otherwise?

That's a good question, and that's why I'm exploring different comparisons
in Python, trying to understand what Python already does, and the pros and
cons thereof, before I suggest anything new.

> Would you prefer a __sort__ method to specify sort order?

Well, there are an infinite number of sort orders. Most of them are pretty
much useless, but even if we limit ourselves to common, useful sort
orders, there are still a good half dozen or more.

So at this time, I'd rather not be pinned down to some half-baked
"solution" before I have even understood the problem.

> And how would you sort a list of complex numbers?

>> Then there is this:
>>
>>>>> 1 > 0
>> True
>
> Okay.
>
>>>>> 1+0j == 1
>> True
>
> Okay.
>
>>>>> 1+0j == 1 > 0
>> True
>
> (1+0j == 1) yields True, which is comparable to 0.

No, 1+0j == 1 > 0 is calculated as 1+0j == 1 and 1 > 0.

>>>>> 1+0j > 0
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> TypeError: cannot compare complex numbers using <, <=, >, >=
>
> But complex numbers are not greater or littler than others. You can't order them,
> not on a one-dimensional scale.

Of course you can order them. You are confusing order with magnitude. The
two are not identical, although they are similar enough in some contexts
as to cause confusion. I admit that I haven't fully grasped all the
subtleties of the general ordering problem. Fortunately, my needs are much
less lofty.

--
Steven.

```