why (1, 2, 3) > [1, 2, 3] is true?

Iain King iainking at gmail.com
Thu Feb 25 09:22:53 EST 2010


On Feb 25, 2:03 pm, fat bold cyclop <fat.bold.cyc... at gmail.com> wrote:
> > Both are not equal, so the comparison returns an arbitrary result in Py2.
>
> Thanks, Stefan. If I understand you correctly the comparison is not
> valid.
> But I wonder if there is any logic behind this (in 2.x).
> Is it possible to predict result of this comparison?
>
> Thanks again,
> fbc

I haven't looked in the source to check (and I'm almost 100% certain
that tuple > list is an implementation detail), but I have not found
any pair of tuple and list in which the list is treated as the
greater.  Possibly related: type(tuple()) is > type(list()). Or, to
let the interpreter tell you why (1,2,3) > [1,2,3]:

>>> tuple > list
True

Iain



More information about the Python-list mailing list