Are there any list comparison optimizations in Python?
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Wed Nov 14 16:59:44 EST 2001
On Wed, 14 Nov 2001 07:32:07 -0800, Emile van Sebille <emile at fenx.com> wrote:
>
>"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
>news:slrn9v2qc7.1ss.huaiyu at gauss.almadan.ibm.com...
>>
>> class A:
>> def __cmp__(a,b): return -1
>>
>> a = [A()]*3
>> a == a # returns 0
>> a is a # returns 1
>>
>>
>> Is this intended?
>
>Yes, as decreed by the author of class A.
>
>
> I would think that mandating
>> a is b implies a == b
>> would make programs easier to read.
>>
>
>Because it's in the class that way, you'd have to assume the author knew
>what was intended.
I made up the example just to show the issue. Can someone think of a real
world example where this is useful? If it's not like this until recently,
was it a feature missed by users in the past? Is the special case
introduced by NaN worth changing the behvior in all the other cases?
Huaiyu
More information about the Python-list
mailing list