Incomparable abominations

Tim Peters tim.one at comcast.net
Sat Mar 22 23:17:08 EST 2003


[Lulu of the Lotus-Eaters]
> I have no particular desire to have sorting work identically between
> platforms, versions, or even different interpreter runs.  As I wrote
> before, I just want it consistent *within* an interpreter run.

Yes, I saw that before, and it's unclear why you're repeating it.  As I
explained in the post to which you're replying here, inconsistency across
runs creates real problems for real apps.  What I haven't seen from you is
*why* you want sorting "to work" even when comparison results are pulled out
of thin air.  David Eppstein gave one use case (comparing sets represented
as lists for equality), almost certainly better done a different way (with
dicts, as explained before).  What's your use case?

> That is to say, I want the following function always to return True:
>
>     def WantTrue(*l):
>         m = list(l)
>         n = list(l)
>         m.sort()
>         n.sort()
>         return m == n
>
> My desire was fulfilled for Python 1.5.2 and every earlier version, btw
> (the only caveat I can think of is if the builtin 'list' was
> overridden).  Python 2.0 broke the desideratum for the new Unicode
> objects (sometimes) [*].

It would be hard to pick a worse example than that, don't you think?
Comparing regular strings to Unicode strings is comparing two kinds of
strings, and if a regular string can't be *meaningfully* converted to
Unicode, making up a nonsense result based on the memory addresses of the
strings seems plain harmful -- the result, and the sort, has nothing to do
with the string contents then.  Python wasn't designed on the principle of
maximal surprise <0.5 wink>.

> Python 2.1 broke it worse for complex numbers.

Yes, but what of it?  Do you actually sort lists containing complex numbers?
If so, I do believe you'll be the first to claim such a hobby.

> Yours, Lulu...
>
> [*] I'm not positive whether 1.6 has Unicode, actually.

1.6 was the first version with builtin Unicode support, but 2.0 was released
less than 24 hours later.






More information about the Python-list mailing list