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 [25]: s = set() In [26]: s.add(Person('kracekumar', 25)) In [27]: s Out[27]: set([<__main__.Person at 0x1033c5e10>]) In [29]: Person('kracekumar', 25) in s Out[29]: False Implement equality check Even though Person object with same value is present but check failed. [Read More]
python  set