title: Python: get item from set based on key
body: <p>I have a class with a custom hash method.</p>
  
  <pre><code>class Test(object):
  
      def __init__(self, key, value):
          self.key = key # key is unique
          self.value = value
  
      def __hash__(self):
          # 'value' is unhashable, so return the hash of 'key'
          return hash(self.key)
  </code></pre>
  
  <p>I make a <code>set</code> using objects of this class.</p>
  
  <pre><code>t0, t1, t2 = Test(0, 10), Test(1, 5), Test(2, 10)
  s = set([t0, t1, t2])
  </code></pre>
  
  <p>Now, is there any way to find objects from <code>s</code> using <code>key</code>? i.e. I want to do:</p>
  
  <pre><code>find_using_key(s, 1) # should return [t1]
  </code></pre>
  
  <p>I know I can do this by iterating over the items in the set, but I feel like there should be an O(1) method to do this since <code>key</code> effectively determines the 'position' in the <code>set</code>.</p>