Python 3.0 - is this true?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Nov 9 00:08:45 EST 2008


On Sat, 08 Nov 2008 19:06:14 -0800, walterbyrd wrote:

> On Nov 8, 7:44 pm, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
> 
>> Define your own ordering if you need to sort incomparable types.
> 
> If you starting new, I suppose you can always work around this new
> enhancement. But, couldn't this cause a lot of  backward compatibility
> issues?

Which is why the change has only been introduced into Python 3, and not 
Python 2.x.

 
> Also, I thought that part of the python philosophy was to allow any sort
> of object in a list, and to allow the same methods to work with whatever
> was in list.

You wouldn't expect this to work would you?

sum( [1, 2, None, "a string", {'x': 5}, []] )

You can only sum objects which are compatible. You can only sort objects 
which define an order: you can't sort lists containing complex numbers 
because "greater than" and "less than" aren't defined for complex 
numbers, and in Python 3 you will no longer be able to order mixed 
objects unless they are intrinsically comparable (e.g. floats and ints), 
unless you define your own order. 



-- 
Steven




More information about the Python-list mailing list