Comparison oddities

Aahz Maruch aahz at panix.com
Fri Feb 2 14:10:46 EST 2001


In article <mailman.981140164.1422.python-list at python.org>,
Chuck Esterbrook  <echuck at mindspring.com> wrote:
>
>It appears that tuples and strings are "greater than" lists.
>Does this seem a little odd to anyone?
>
>Since tuples and lists are both "sequences of anything", you would hope 
>that they would compare in "the natural fashion".
>
>Since comparing a string and a list doesn't make sense, would an exception 
>be more appropriate?
>
>And yes, I know the manual says "Otherwise, objects of different types 
>*always* compare unequal, and are ordered consistently but arbitrarily. ... 
>In the future, the comparison rules for objects of different types are 
>likely to change."
>
>My question is more of a design question.

I'm only going to answer your second question: this ordering is required
by the fact that lists are *not* homogenous.  A list can contain any
other Python type, including lists, strings, dicts, and numbers.
list.sort() is required to work well in all of this.
-- 
                      --- Aahz (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"People sometimes focus too much on the fact of communication rather than
the substance of communication."  --Dave Morton



More information about the Python-list mailing list