Comparison of functions
tiissa at nonfree.fr
Sat Jul 30 18:49:27 CEST 2005
Steven D'Aprano wrote:
> 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.
The point is Python does not.
The order you proposed above can be implemented using a comparison
function you can pass to the sort function of lists  or the sorted
If the elements can be compared, Python offers you not to pass the cmp
function to sort if you want to use this default order.
Python allows you to use the default ordering to sort a list but does
not treat both questions in the same manner. However, the fact is
ordering a list using the default '<' happens pretty often.
In the case of complex numbers, no mathematically sound comparison
function exists and Python does not impose some default function that
would be called a wart.
More information about the Python-list