A suspected bug

Andrew Dalke dalke at acm.org
Sat Feb 17 22:02:23 EST 2001


Aahz Maruch wrote:
>What should the following code do:
>
>foo = [1, '2']
>foo.sort()
>
>Because Python lists can contain heterogeneous information, the
>comparison operators *must* work between types.

That's what I used to think was the accepted Python view
of the world, but from the update info for Python 2.1

]- Complex numbers use rich comparisons to define == and != but raise
]  an exception for <, <=, > and >=.  Unfortunately, this also means
]  that cmp() of two complex numbers raises an exception when the two
]  numbers differ.  Since it is not mathematically meaningful to compare
]  complex numbers except for equality, I hope that this doesn't break
]  too much code.

so foo.sort() won't even work for all built-in homogenous data
types.

'Course, I would prefer that complex numbers had a sort, even
if not "mathmatical".  There are a couple of ways to do it,
but I don't want to get into that tangent.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list