title: Python data structure for a collection of objects with random access based on an attribute
body: <p>I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
  Here is an example of what I have now:</p>
  
  <pre><code>class Item():
      def __init__(self, uniq_key, title=None):
          self.key = uniq_key
          self.title = title
  
  item_instance_1 = Item("unique_key1", title="foo")
  item_instance_2 = Item("unique_key3", title="foo")
  item_instance_3 = Item("unique_key2", title="foo")
  
  item_collection = {
          item_instance_1.key: item_instance_1,
          item_instance_2.key: item_instance_2,
          item_instance_3.key: item_instance_3
          }
  
  item_instance_1.key = "new_key"
  </code></pre>
  
  <p>Now this seems a rather cumbersome solution, as the key is not a reference to the attribute but takes the value of the key-attribute on assignment, meaning that:</p>
  
  <ul>
  <li>the keys of the dictionary duplicate information already present in form of the object attribute and</li>
  <li>when the object attribute is changed the dictionary key is not updated.</li>
  </ul>
  
  <p>Using a list and iterating through the object seems even more inefficient.</p>
  
  <p>So, is there more fitting data structure than dict for this particular case, a collection of objects giving me random access based on a certain object attribute?</p>
  
  <p>This would need to work with Python 2.4 as that's what I am stuck with (at work).</p>
  
  <p>If it hasn't been obvious, I'm new to Python.</p>