title: How do I use __getitem__ and __iter__ and return values from a dictionary?
body: <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
  
  <p>For example:</p>
  
  <pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10) 
  &gt;&gt;&gt; class Library(object):
  ...   def __init__(self):
  ...     self.books = { 'title' : object, 'title2' : object, 'title3' : object, }
  ...   def __getitem__(self, i):
  ...     return self.books[i]
  ... 
  &gt;&gt;&gt; library = Library()
  &gt;&gt;&gt; library['title']
  &lt;type 'object'&gt;
  &gt;&gt;&gt; for book in library:
  ...   print book
  ... 
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 5, in __getitem__
  KeyError: 0
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>How do I tell it to simply return the <code>object</code> for each item in the dictionary (the key doesn't matter) ?</p>