Python 3.0, rich comparisons and sorting order

Carlos Ribeiro carribeiro at gmail.com
Tue Sep 21 14:07:30 EDT 2004


On Tue, 21 Sep 2004 17:24:48 +0000 (UTC), Steven Bethard
<steven.bethard at gmail.com> wrote:
> Could you give an example of a list that you'd like to do this to?  I'm still
> having trouble imagining a list of disparate types that I call sort on...

Assume that you're implementing a spreadsheet like application in
Python. The user fills a column with arbitrary data, and asks for it
to be sorted. What is the sorting order? Excel, for instance, defines
an ordering (it's arbitrary, but it's deterministic).

Let me put it another way:

sort() should work regardless of the list elements, and return a
reasonable result, even if not strictly correct in the numerical
sense.

And my last argument, and probably the most controversial one, and the
one that will see me tortured, killed and nailed to the city door for
visitors to see what happen with people that pushes the social limits
:-) Mathemathically speaking: sort() is not a topological sort (which
works with partial ordering); it implements total ordering (any two
members of the set can be compared). The set, in this particular case,
is a Python list, that *can* contain arbitrary data. So it does not
make sense (in my not-so-humble opinion) for sort to impose
restrictions based on the list element type.

(BTW, if we extend this reasoning, the same could be said for other
types of functions that work over sets -- sum() should ignore
non-numeric values, etc. But that's another philosophical battle)

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list