Sorting a list with entries of unequal types
Ben Finney
ben+python at benfinney.id.au
Thu Jan 28 19:01:21 EST 2010
Howdy all,
Python 2.6 tells me that, in Python 3, sorting a list with entries of
incompatible types is not allowed:
=====
$ python2.5 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort(); print foo;"
[-27, 1, True, 4, 15.300000000000001, 'green']
$ python2.6 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort(); print foo;"
[-27, 1, True, 4, 15.300000000000001, 'green']
$ python2.6 -3 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort(); print foo;"
-c:1: DeprecationWarning: comparing unequal types not supported in 3.x
[-27, 1, True, 4, 15.300000000000001, 'green']
=====
So how should I be sorting a list with entries of “unequal types” such
that it will work in Python 3?
--
\ “The idea that He would take his attention away from the |
`\ universe in order to give me a bicycle with three speeds is |
_o__) just so unlikely that I can't go along with it.” —Quentin Crisp |
Ben Finney
More information about the Python-list
mailing list