title: Python Object as Dict Key using __hash__ for access
body: <p>Take this super simple class:</p>
  
  <pre><code>class Foo():
      def __init__(self, iden):
          self.iden = iden
      def __hash__(self):
          return hash(self.iden)
      def __repr__(self):
          return str(self.iden)
  </code></pre>
  
  <p>The goal is to create instances of the class to use as dict keys.  If <code>__repr__</code> is omitted, the keys are the standard object address.  With <code>__repr__</code> a printable representation might be:</p>
  
  <pre><code>f = Foo(1)
  g = Foo(2)
  d = {f:'a', g:'b'}
  print(d)
  &gt;&gt;&gt; {1:'a', 2:'b'}
  </code></pre>
  
  <p>When attempting to access the dict by key though, it does not appear to be immediately obvious how to utilize the <code>__repr__</code> (or <code>__str__</code> for that matter) representation as the key.</p>
  
  <pre><code>print(d[1]) 
  &gt;&gt;&gt; KeyError
  </code></pre>