Comparisons of incompatible types
John Nagle
nagle at animats.com
Wed Dec 8 17:49:55 EST 2010
On 12/8/2010 1:47 AM, Steven D'Aprano wrote:
> On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote:
>
>> Carl Banks<pavlovevidence at gmail.com> writes:
>>
>>> On Dec 6, 4:17 pm, Steven D'Aprano<steve
>>> +comp.lang.pyt... at pearwood.info> wrote:
>>>> Nevertheless, I agree that in hindsight, the ability to sort such
>>>> lists is not as important as the consistency of comparisons.
>>>
>>> I think that feeling the need to sort non-homogenous lists is
>>> indicative of bad design.
>>
>> It can also be indicative of code written for a Python that doesn't have
>> sets.
>
> Or a list that contains unhashable objects.
If you can't hash it, and it doesn't have some definition of
comparison associated with the object, you probably can't order
it properly, either.
"<" can't be some random function. For sorting to work,
a < b and b < c implies a < c
must hold.
John Nagle
More information about the Python-list
mailing list