class A(): def __init__(self, data=\'\'): self.data = data def __str__(self): return str(self.data) d = {} elem = A() d[elem] = \'abc\'
What you did should work, as long as you don't override the __hash__() and __eq__() methods. It will use object identity as equality. If you want a different notion of equality, you can override the __hash__() and __eq__() methods of your class.
__hash__()
__eq__()