title: print a dictionary of dictionaries to a csv?
body: <p>I have a dictionary that looks like this: </p>
  
  <pre><code>defaultdict(&lt;type 'int'&gt;, {'201304': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201305': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201306': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201301': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201302': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201303': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2}), '201212': defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})})
  </code></pre>
  
  <p>I want a cvs that looks like this:</p>
  
  <pre><code>month,District - 1,District -2, District -3...... for however many districts there are 
  201304,20,9,5,6,..... 
  </code></pre>
  
  <p>what I have right now is: </p>
  
  <pre><code>with open('output.csv','wb') as output_file:
      w= csv.writer(output_file)
      w.writerows(months.items())
  </code></pre>
  
  <p>months is the name of my dictionary described above. Unfortunately it outputs: </p>
  
  <pre><code>201304  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201305  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201306  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201301  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201302  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201303  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  201212  defaultdict(&lt;type 'int'&gt;, {'District - 1': 20, 'District - 12': 9, 'District - 6': 5, 'District - 5': 1, 'District - 4': 1, 'District - 3': 1, 'District - 2': 13, 'District - 15': 1, 'District - 14': 2})
  </code></pre>
  
  <p>What I need is 1 row for each month:</p>
  
  <pre><code>month,District - 1,District -2, District - 3, .... (as many as show up)
  201304,22,34,2,3,4,2,3,14
  201305,34,22,1,3,5
  201306,23,4,42,4,2,2,24,2,5,6,6,7,1
  </code></pre>
  
  <p>Any suggestions on how to modify my code to do this?</p>