fork download
  1. class SomeClass(object):
  2. someattribute = "somevalue"
  3. def __eq__(self, other):
  4. return self.someattribute == other.someattribute
  5. def __hash__(self):
  6. return hash(self.someattribute)
  7. def __ne__(self, other):
  8. return not self.__eq__(other)
  9.  
  10. list_of_objects = [SomeClass()]
  11. print(SomeClass() in list_of_objects)
  12.  
  13. set_of_objects = set([SomeClass()])
  14. print(SomeClass() in set_of_objects)
  15.  
Success #stdin #stdout 0.02s 5864KB
stdin
Standard input is empty
stdout
True
True