title: Iterating over dictionaries of lists
body: <p>I have a dictionary (dict_of_lists) that has as its values a list of tuples (inside_list). I populate the dictionary with 10 entries, with each entry consisting of a list of 100 tuples. The code to do this is as follows:</p>
  
  <pre><code>inside_list = []
  dict_of_list = collections.defaultdict(list)
  for j in range(0, 10):
      for i in range(0, 100):
          inside_list.append((j, i))
      dict_of_list[j].append(inside_list)
  </code></pre>
  
  <p>Now, to iterate the dictionary and print just the second value of all the tuples in the lists inside_list (that is, the j values), I was thinking that I would need to use 2 for loops, one to iterate the dictionary, and the other to iterate the inside_list. So I wrote the following:</p>
  
  <pre><code>for k in dict_of_list.keys():
      for item in dict_of_list[k]:
          print(item[1])
  </code></pre>
  
  <p>However, the results that I recive is:</p>
  
  <pre><code>(0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  (0, 1)
  </code></pre>
  
  <p>My question is, why isn't "item" the tuples of the lists inside_list, and instead, it looks that it's the complete inside_list instead?</p>
  
  <p>To fix this, I added another for loop:</p>
  
  <pre><code>for k in dict_of_list.keys():
      for item in dict_of_list[k]:
          for x in item:
            print(x[1])
  </code></pre>
  
  <p>But then, what was the use of the for loop statement "for item in dict_of_list[k]" in the first place?</p>