Check for custom objects in Python set.
Python set data structure is commonly used for removing duplicate entriesand make lookup faster (O(1)). Any hashable object can be stored in set.For example, list and dict can’t be stored. User defined objects can be stored. Here is how it looks. class Person(object): def __init__(self, name, age): self.name, self.age = name, age In : s = set() In : s.add(Person('kracekumar', 25)) In : s Out: set([<__main__.Person at 0x1033c5e10>]) In : Person('kracekumar', 25) in s Out: False Implement equality check Even though Person object with same value is present but check failed. [Read More]