Peter Otten __peter__ at
Thu Aug 19 16:47:46 CEST 2010

Karsten Wutzke wrote:

> I have an object which has a list of other complex objects. How do I
> best achieve a complex "contains" comparison based on the object's
> class? In Java terms, I'm looking for an equivalent to equals(Object)
> in Python. Does a similar thing exist? Directions appreciated.

I can't infer from your question whether you already know about 
__contains__(). So there:

>>> class Cornucopia:
...     def __contains__(self, other):
...             return True
>>> c = Cornucopia()
>>> 42 in c
>>> "cherry pie" in c
>>> c in c

More information about the Python-list mailing list