title: Python iterating over a dictionary
body: <p>for some reason I just can't iterate over a dictionary in Python. I've done it before but somehow I can't make it happen anymore. I feel like I'm missing something obvious although I don't know what exactly. I am currently learning Python at <a href="http://learnpythonthehardway.com/book" rel="nofollow">http://learnpythonthehardway.com/book</a> Exercise 48. Using Nosetests and a given testcode I should then code the according code in the actual script to make the test work. Here is the code in the testfile:</p>
  
  <pre><code>from nose.tools import *
  from ex48 import lexicon
  
  
  def test_directions():
      assert_equal(lexicon.scan("north"), [('direction', 'north')])
      result = lexicon.scan("north south east")
      assert_equal(result, [('direction', 'north'),
                            ('direction', 'south'),
                            ('direction', 'east')])
  </code></pre>
  
  <p>So now I wrote this code to make the test work:</p>
  
  <pre><code>lex = { 'dir':'north', 'dir':'south', 'dir':'east', 'dir':'west', 
          'dir':'down', 'dir':'up', 'dir':'left', 'dir':'right', 
          'verb':'go', 'verb':'stop', 'verb':'kill', 'verb':'eat', 
          'stop':'the', 'stop':'in', 'stop':'of', 'stop':'from', 'stop':'at', 'stop':'it',
          'noun':'door', 'noun':'bear', 'noun':'princess', 'noun':'cabinet'}
  
  def scan(word):
      for k in lex:
          if lex[k] == word:
              return (k, word)
      return None
  </code></pre>
  
  <p><code>assert_equal()</code> just checks if both parameters are the same.
  I am pretty sure this should work but anyway I changed it according to the Python documentation:</p>
  
  <pre><code>def scan(word):
      for k, v in dict.iteritems():
      if v == word:
          return (k, word)
      return None
  </code></pre>
  
  <p>Both ways just throw a <code>None</code> back at me and I just can't figure out why.</p>