You must add the __eq__ and __hash__ to your Data class, it can check if the __dict__ attributes __dict__ equal (the same properties), and then if their values are equal.
If you have done this, you can use
test = Data() test.n = 5 found = test in myList
The in keyword checks if test in myList .
If you want only the a n property in Data , you can use:
class Data(object): __slots__ = ['n'] def __init__(self, n): self.n = n def __eq__(self, other): if not isinstance(other, Data): return False if self.n != other.n: return False return True def __hash__(self): return self.n myList = [ Data(1), Data(2), Data(3) ] Data(2) in myList
Johannes Weiß Feb 28 '09 at 18:10 2009-02-28 18:10
source share