title: How can I make my classes usable as dict keys?
body: <pre><code>class A():
     def __init__(self, data=''):
         self.data = data  
  
     def __str__(self):
         return str(self.data)
  
  d = {}  
  elem = A()  
  d[elem] = 'abc'  
  
  elem2 = A()
  print d[elem2]    # KeyError  
  # actually elem2! was used not elem
  </code></pre>
  <p>how can I implement this without error?</p>
  <p>I tried to get <code>d[elem2]</code> (not <code>elem</code>) with another instance of A() BUT with the same content.</p>