Thursday, January 29, 2009

Chapter 4 -- Page 128 -- Problem 4.2g

In Python3.0, the sort method will not work across different data types. Performing sort on the list in this problem will cause an error.

>>> alist
[7, 9, 'a', 'cat', False]
>>> alist.sort()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()

No comments:

Post a Comment