I'm trying to find a way how to compare objects in sets to make & operator work properly on them.
I was trying to find source codes to Set function intersect()
, but hopelessly. I have tried to overload the equals operator, but when I added __eq__()
function into the class definition, the Person objects became unhashable.
class Person:
def __init__(self, dictionary):
self.dictionary = dictionary
def foo1():
first_set.add(Person({"age" : 20}))
def foo2():
second_set.add(Person({"age" : 20}))
first_set = set()
second_set = set()
foo1()
foo2()
print(first_set)
print(second_set)
print(first_set & second_set) # I'd like to get non-empty intersection here
I thought it could work somehow with __eq__()
overloading, but it's not possible.