> masteringswe_
codingpython

Override hash

Add a method to class Point so that Point objects can be used in sets or as dictionary keys.

pythonclass Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

p1 = Point(1, 2)
p2 = Point(1, 2)

s = set()
s.add(p1) # Should not throw "unhashable type" when it's fixed