f

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

```I tired to google for comparison of tuple to list but i failed.

Could anyone explain it to me?

Best regards,
fat bold cyclop
```
 0
2/25/2010 1:00:48 PM
comp.lang.python 77058 articles. 6 followers.

7 Replies
960 Views

Similar Articles

[PageSpeed] 30

```fat bold cyclop, 25.02.2010 14:00:
> I tired to google for comparison of tuple to list but i failed.
>
> Could anyone explain it to me?

Both are not equal, so the comparison returns an arbitrary result in Py2.

Note that this was fixed in Py3:

Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
[GCC 4.4.1] on linux2
>>> (1,2,3) > [1,2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: tuple() > list()

Stefan

```
 0
stefan_ml (868)
2/25/2010 1:46:56 PM
```> 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
```
 0
2/25/2010 2:03:03 PM
```On Feb 25, 2:03=A0pm, fat bold cyclop <fat.bold.cyc...@gmail.com> wrote:
> > Both are not equal, so the comparison returns an arbitrary result in Py=
2.
>
> 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 believe in 2.x they are ordered by the names of their types but I
could be wrong.

1 < [] < '' < () < u''
```
 0
chardster (21)
2/25/2010 2:21:56 PM
```On Feb 25, 2:03=A0pm, fat bold cyclop <fat.bold.cyc...@gmail.com> wrote:
> > Both are not equal, so the comparison returns an arbitrary result in Py=
2.
>
> 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
```
 0
iainking (148)
2/25/2010 2:22:53 PM
```fat bold cyclop, 25.02.2010 15:03:
>> 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?

The result is predictable, it's just arbitrary in that it does not depend
on the values that you are comparing but only on their type.

Stefan

```
 0
stefan_ml (868)
2/25/2010 2:54:58 PM
```On 2/25/2010 9:21 AM, Richard Thomas wrote:
> On Feb 25, 2:03 pm, fat bold cyclop<fat.bold.cyc...@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?

In general, no. The result is arbitrary, with the constraint of being
consistent within a particular run.

>> Thanks again,
>> fbc
>
> I believe in 2.x they are ordered by the names of their types but I
> could be wrong.

This is currently true in *CPython* 2.x, but that is an implementation
artifact that has changed and might be different with other implementations.

Terry Jan Reedy

```
 0
tjreedy (5460)
2/25/2010 6:27:11 PM
```On Feb 25, 7:00=A0am, fat bold cyclop <fat.bold.cyc...@gmail.com> wrote:
> why (1, 2, 3) > [1, 2, 3] is true?

It's simple, Everything must have a value!
```
 0
rt8396 (474)
2/26/2010 12:29:13 AM