sort mixed values
examples/lists/sort_mixed.py
mixed = [100, 'foo', 42, 'bar'] print(mixed) mixed.sort() print(mixed)
In Python 3 it throws an exception.
[100, 'foo', 42, 'bar'] Traceback (most recent call last): File "examples/lists/sort_mixed.py", line 5, in <module> mixed.sort() TypeError: unorderable types: str() < int()
Python 2 puts the numbers first in numerical order and then the strings in ASCII order.
[100, 'foo', 42, 'bar'] [42, 100, 'bar', 'foo']