"a in b" calls a.__cmp__, why?

Steven Taschuk staschuk at telusplanet.net
Sat Jun 21 16:21:46 EDT 2003


Quoth Gerrit Holl:
> Why does a container-sequence's __contains__ call obj.__cmp__?

Imagine an implementation of list.__contains__:

    def __contains__(self, sought):
        for obj in self:
            if obj == sought:
                return True
        else:
            return False

Note the comparison.  How else would it know whether object X
found in the list is the same as object Y being sought?

-- 
Steven Taschuk                            staschuk at telusplanet.net
"Our analysis begins with two outrageous benchmarks."
  -- "Implementation strategies for continuations", Clinger et al.





More information about the Python-list mailing list