Python 3.0 - is this true?
steven at REMOVE.THIS.cybersource.com.au
Mon Nov 10 10:52:04 CET 2008
On Sun, 09 Nov 2008 10:45:31 -0500, Roy Smith wrote:
> As another example, consider a list of items being juggled:
> [RubberChicken(), ChainSaw(), Canteloupe()]
> I could go through contortions to find some common subclass for these
> items, but the whole *point* is that they're not of the same type. And
> making a list of them is a perfectly reasonable thing to do.
Absolutely, and Python 3 does not prevent you from making a list of them.
However, sorting them is *not* a reasonable thing to do, just like
summing them is not a reasonable thing to do, and Python 3 does prevent
you from sorting (or summing) them without extra work.
If you've been relying on Python 2.x's "take a guess and hope it works"
heuristic for sorting uncomparable types, this will come across as a
nuisance. Sorry. I'm afraid you only have two choices in Python 3:
(1) find some way to avoid sorting such data; or
(2) bite the bullet and spend the time required to define your own
ordering relationships between types. After all, you can sort by
*anything* once you give Python an appropriate key function.
More information about the Python-list