#!/usr/local/bin/python2 class C(object): def __init__(self, name): self.name = name def __eq__(self, o): if not isinstance(o, C): return NotImplemented return self.name == o.name def __hash__(self): return hash((self.__class__, self.name)) c = C(1) c2 = C(1) c3 = C(3) d = {c: 1, c3: 3, c2: 2} print d, c == c2, c == c3, c2 == c3