title: Dictionary Iterating -- for dict vs for dict.items()
body: <p>When we iterate over the dictionary below, each iteration returns(correctly) a key,value pair  </p>
  
  <pre><code>for key, value in dict.items():
      print "%s key has the value %s" % (key, value)
  </code></pre>
  
  <p><code>'some key'</code> key has the value <code>'some value'</code> (repeated however many times there are a k,v pair)</p>
  
  <p>The above makes sense to me, however if we do this:</p>
  
  <pre><code>for key in dict.items():
      print "%s key has the value %s" % (key, value)
  </code></pre>
  
  <p><code>("some key", "some value")</code> has the value <code>"some value"</code> (the left tuple will iterate through each key value pair and the right value will just stay at the first value in the dict and repeat)</p>
  
  <p>We end up getting each k,v pair returned in the first <code>%s</code> (key) and the 2nd <code>%s</code> (value) does not iterate, it just returns the first value in the dict for each iteration of the for loop.</p>
  
  <p>I understand that if you iterate with only <code>for key in dict</code> then you are iterating over the keys only.  Here since we are iterating a set of tuples (by using <code>dict.items()</code>) with only the key in the for loop, the loop should run for the same number of times as the first example, since there are as many keys as key,value pairs.</p>
  
  <p>What I'm having trouble grasping is why python gives you the entire tuple in the second example for <code>key</code>.</p>
  
  <hr>
  
  <p>Thanks for the help all -- I'd like to add one more question to the mix.</p>
  
  <pre><code>for a,a in dict.items():
      print a
  </code></pre>
  
  <p>Why does the above print the value, and if i <code>print a,a</code> - obviously both values are printed twice.  If I had typed <code>for a,b</code> I would be iterating <code>(key,value)</code> pairs so I would logically think I am now iterating over <code>(key,key)</code> pairs and would therefore print key rather than value.  Sorry for the basic questions just playing around in interpreter and trying to figure stuff out.</p>