I come from C++ and am new to Python. I have a class as follows.
class pair:
u=0
v=0
def __init__(self, x,y):
self.u=x
self.v=y
def __eq__(self,ot):
if self.u==ot.u and self.v==ot.v:
return True
return False
I want a function that returns the intersection of two lists of pairs.
def intersection(P,Q):
return len(set(P).intersection(set(Q)))
and I get this error:
TypeError: unhashable type: 'pair'
Coming from C++ I don't understand why it is not allowed to turn a list like this to a set. Can one take an immutable snapshot of the list to make the set?