Performance of list vs. set equality operations

Terry Reedy tjreedy at udel.edu
Thu Apr 8 12:26:48 CEST 2010


On 4/8/2010 3:07 AM, Steven D'Aprano wrote:
> On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote:
>
>> [Raymond Hettinger]
>>>> If the two collections have unequal sizes, then both ways immediately
>>>> return unequal.
>>
>> [Steven D'Aprano]
>>> Perhaps I'm misinterpreting what you are saying, but I can't confirm
>>> that behaviour, at least not for subclasses of list:
>>
>> For doubters, see list_richcompare() in
>> http://svn.python.org/view/python/trunk/Objects/listobject.c?
> revision=78522&view=markup
>
> So what happens in my example with a subclass that (falsely) reports a
> different length even when the lists are the same?
>
> I can guess that perhaps Py_SIZE does not call the subclass __len__
> method, and therefore is not fooled by it lying. Is that the case?

Adding a print call within __len__ should determine that.






More information about the Python-list mailing list