Why is tuple larger than a list in python?
python, python-2.7
Solution
From the docs:
The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily. You can control comparison behavior of objects of non-builtin types by defining a `__cmp__` method or rich comparison methods like `__gt__`, described in section 3.4.
(This unusual definition of comparison was used to simplify the definition of operations like sorting and the in and not in operators. In the future, the comparison rules for objects of different types are likely to change.)
Which is true. In python 3 this is a `TypeError`.
() > []
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-d2326cfc55a3> in <module>()
----> 1 () > []
TypeError: unorderable types: tuple() > list()
Back to python 2: The docs stress that this is an arbitrary, but consistent ordering.
In cPython 2, unequal types are compared by their type name. So `tuple` is "greater than" `list`, lexicographically.
Problem
Consider following problem in Python: ``` >>> () < [] ``` this statement yield `False` and ``` >>> () > [] ``` yields True. So far as I know, `[]` equals `False`, but what is an empty tuple ? If we type ``` >>> 1233 < (1,2) ``` We get a `True`, as return value. But why ? Thanks