[Python-Dev] Re: lists v. tuples

Alex Martelli aleax@aleax.it
Sat, 15 Mar 2003 19:07:35 +0100

On Saturday 15 March 2003 04:59 pm, Christian Tismer wrote:
> Complex just has no total order, which makes it impossible to
> provide a meaningful default ordering.

Back in Python 1.5.2 times, the "impossible to provide" ordering
was there.  No more (and no less!) "meaningful" than, say,
comparisons between (e.g.) lists, numbers, strings and dicts,
which _are_ still provided as of Python 2.3.

> I agree that my statement does not apply when putting
> non-sortable things into a list. But I don't believe

A list containing ONE complex number and (e.g.) three
strings is sortable.  So, there are NO "non-sortable things".

A list is non-sortable (unless by providing a custom compare,
as you pointed out) if it contains a complex number and any
other number -- so, there _are_ "non-sortable LISTS" (unless
suitable custom compares are used), but still no "non-sortable
THINGS" in current Python.

> that people are putting widely different types into
> a list in order to sort them. (Although there is an
> arbitrary order between strings and numbers, which
> I would drop in Python 2.4, too).

Such a change would indeed enormously increase the
number of non-sortable (except by providing custom
compares) lists.  So, for example, all places which get
and sort the list of keys in a dictionary in order to return 
or display the keys should presumably do the sorting
within a try/except?  Or do you think a dictionary should
also be constrained to have keys that are all comparable
with each other (i.e., presumably, never both string AND
number keys) as well as hashable?

I fail to see how forbidding me to sort the list of keys of
any arbitrary dict will enhance my productivity in any way --
it's bad enough (in theory -- in practice it doesn't bite much
as complex numbers are used so rarely) with the complex
numbers thingy, why make it even worse by inventing a
novel "strings vs numbers" split?

Since when is Python about forbidding the user to do
quite normal things such as sorting the list of keys of
any arbitrary dictionary for more elegant display -- for
no practically useful purpose that I've ever seen offered,
in brisk violation of "practicality beats purity"?