Python 3.0 - is this true?

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Sun Nov 9 12:01:41 EST 2008


Steven D'Aprano writes:
> How often do you care about equality ignoring order for lists containing 
> arbitrary, heterogeneous types?

Arbitrary, I never have.  Different types of my choice, a few times.
I was only interested in there being some _sort_ order (and the same in
different runs of the program), not in what the sort order was.

However string sorting is partly arbitrary too.  It depends on the
code points in the string's character set.  u'\u00c5' < u'\u00d8'
(u'Å' < u'Ø') is wrong in Norwegian.  '0' < 'B' < 'a' < '~' can be
wrong depending on the application, as can '10' < '5'.

So I don't quite buy the argument about arbitrary sorting.  If you have
different types, at least you likely know that you are doing something
weird.  OTOH it's quite common - even normal - to produce poor sort
results because one depends on the built-in arbitrary string sort order.


In any case, would it be possible to add a cmp= function which did more
or less what the current default cmp does now?  Then it's available when
someone wants it, and the "arbitrariness" of different types is not
inflicted on people who don't.  (In my case I _think_ it's just a "nice
to have" to me and nothing more, but I don't remember for sure.)

-- 
Hallvard



More information about the Python-list mailing list