[Python-Dev] Re: lists v. tuples

Christian Tismer tismer@tismer.com
Sat, 15 Mar 2003 20:50:33 +0100


Alex Martelli wrote:
...

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

Quite an academical POV for a practical man like you.

> 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.

Don't understand: How is a tuple not a non-sortable
thing, unless I turn it into a list, which is not
a tuple? Or do you mean the complex, which refuses
to be sorted, unlike other obejcts, which don't
provide any ordering, and are ordered by ID?

[number/string comparison]

> Such a change would indeed enormously increase the
> number of non-sortable (except by providing custom
> compares) lists.

Theoretical lists, or those existing in real
applications? For the latter, most of the time,
mixing ints and strings was most often a programming
error in my past.

> 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 would like to have sub-classes of dictionaries, which
protect me from putting key into them which I didn't
intend to. But that doesn't mean that I want to
forbid it once and forever.
Concerning general dicts, you are right, sorting the keys
makes sense to get them into some arbitrary order.

> I fail to see how forbidding me to sort the list of keys of
> any arbitrary dict will enhance my productivity in any way --

I thought it would catch the cases where you failed to build
a key of the intended type. Maybe this is worse than what we
have now, tho. I have to say that this wasn't the point of my
message, so I don't care to discuss it.

...

> 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"?

Well, I just don't like such an arbitrary thing, that a
string is always bigger than an int. Since we don't allow
them to use as each other by coercion, we also should not
compare them. Bean counts are bean counts, and names are names.
One could go the AWK way, where ints and strings were concerted
whenever necessaray, but that would be even worse.
Maybe the way Python handles it is not so bad. But then it
sould be consequent and at least move complex objects
into their own group in the sorted array, maybe just not
sorting themselves.

Anyway, this would also not increase your/my productivity
in any way, so let's get back to real problems.

ciao - chris
-- 
Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/