title: Write a dictionary of dictionaries to csv in python
body: <p>I have a dictionary of dictionaries that I would like to write out to csv.  my dictionary looks like:</p>
  
  <pre><code>dict={
      object1:
          {
              time1:[value1,value2],
              time2:[value3,value4]
          },
      object2:
          {
              time1:[value5,value6],time2[value7,value8]
          }
      }
  </code></pre>
  
  <p>I would like it to write out as:</p>
  
  <p><strong>object1</strong></p>
  
  <p>time1, value1, value2</p>
  
  <p>time2, value3, value4</p>
  
  <p><strong>object2</strong></p>
  
  <p>time1, value5, value6</p>
  
  <p>time2, value7, value8</p>
  
  <p>Thus far, I can only figure out how to write the key/value pairs out csv using the following code:</p>
  
  <pre><code>writer = csv.writer(open('test.csv','wb'))
  for key, value in Dict.items():
      writer.writerow([key,value])
  </code></pre>
  
  <p>So it looks like:</p>
  
  <pre><code>objcet1,{
      time1:[value1,value2],time2:[value3,value4]
  }
  
  objcet2,{
      time1:[value5,value6],time2:[value7,value8]
  }
  </code></pre>
  
  <p>I have tried writing just the outer keys (keys labeled object1 and object2) using</p>
  
  <pre><code>writer = csv.writer(open('test.csv','wb'))
  for key, value in Dict.key():
      writer.writerow([key])
  </code></pre>
  
  <p>but it just writes out a blank file.  I think If I could figure out how to write the outer keys by themselves, I would be able to write out the csv as I want.  Does anyone have any suggestions?</p>