Comparison of functions

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Jul 30 14:53:57 EDT 2005


On Sat, 30 Jul 2005 17:57:20 +0000, Adriano Varoli Piazza wrote:

> Steven D'Aprano ha scritto:
> 
>> Do you understand the difference between partial and total ordering, or
>> weakly and strongly ordered? When you do understand them, come back and
>> tell me again whether you still think lexicographic sorting has no meaning
>> whatsoever.
>> 
> 
> I think I answered this in another post... If you want to order text 
> strings (as complex numbers in an index in a book, or in a lexicographic 
> sort are) do so. I understand the importance it has to you, but it's 
> hardly reasonable to argue that Python should do the most unintuitive 
> thing with complex numbers by default just because it suits you.

Adriano, list.sort() is not an operation on complex numbers. It is an
operation on a list. What is unintuitive is that you can't sort a list
merely because of the arithmetical properties of an object in that list.
Why should that make a difference? We're not doing arithmetic on the
objects, we're sorting the list.

It isn't even about *complex numbers* as such -- that was just a
convenient example. There are no end to the possible objects which don't
define greater than and less than. But you should still be able to sort a
list containing them. Sorting is not numeric comparisons!

Python already allows you to compare "this is not a number" with the float
5.0. Mathematically, that is meaningless, but I would bet money that
99.9% of programmers would demand that they should be able to sort the
list ["this is not a number", 5.0]. Do you think that it is unintuitive
too?

This conversation has been an exercise in futility. I'm sorry that so many
of the people answering find it difficult to see the difference between
numeric comparisons of complex numbers (which are rightly forbidden) and
sorting of lists of arbitrary objects (which should always succeed): in
effect, confusing the current implementation of sort() in Python with the
general principle of sorting.

Unless anyone comes up with constructive comments (which does not
necessarily mean "agrees with me"), I plan to drop this thread until such
time, if ever, that I have something more concrete to suggest.


-- 
Steven.




More information about the Python-list mailing list