comparison on list yields surprising result

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Aug 29 04:16:21 EDT 2009


On Sat, 29 Aug 2009 09:36:38 +0200, Hendrik van Rooyen wrote:

> On Friday 28 August 2009 21:00:31 Dr. Phillip M. Feldman wrote:
>> In [21]: x
>> Out[21]: [1, 2, 3, 5]
>>
>> In [22]: x>6
>> Out[22]: True
>>
>> Is this a bug?
> 
> No, it is a feature, so that you can use sorted on this:
> 
> [[1,2,3,4,5],6]


If it's a feature, it has gone away in Python 3.


Python 3.0.1 (r301:69556, Apr  2 2009, 00:41:38)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> [[1,2,3], 5].sort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < list()




-- 
Steven



More information about the Python-list mailing list