title: Writing a list of unpacked tuples to CSV
body: <p>I am trying to write a list of tuples (which is not flat) into a CSV.
  So for example the input would be:</p>
  <pre><code>[(('temperature', 42), ('date', datetime.date(2017, 1, 22)), ('locations', ('Berlin', 'Paris')), ('weather', 'sunny')), 
  (('temperature', -42), ('date', datetime.date(2017, 1, 22)), ('locations', ('Marseille', 'Moscow')), ('weather', 'cloudy'))]
  </code></pre>
  <p>and output should be</p>
  <pre><code>temperature,date,locations,weather
  42,01/22/2017,&quot;Berlin,Paris&quot;,sunny
  -42,01/22/2017,&quot;Marseille,Moscow&quot;,cloudy
  </code></pre>
  <p>However what I am getting is</p>
  <pre><code>temperature,date,locations,weather
  42
  2017-01-22
  &quot;('Berlin', 'Paris')&quot;
  sunny
  -42
  2017-01-22
  &quot;('Marseille', 'Moscow')&quot;
  cloudy
  </code></pre>
  <p>My code looks like this:</p>
  <pre><code>import csv
  import datetime
  
  def generate_csv(a_list):
      with open('results.csv', 'w', newline='') as csvfile:
          writer = csv.writer(csvfile, delimiter=',', quotechar='&quot;')
          #writer.writerow(['temperature','date','locations','weather'])
          for i in a_list:
              for j in i:
                  print(j[1:])
                  writer.writerow(j[1:])
              
  test = [(('temperature', 42), ('date', datetime.date(2017, 1, 22)), ('locations', ('Berlin', 'Paris')),  ('weather', 'sunny')),
  (('temperature', -42), ('date', datetime.date(2017, 1, 22)), ('locations', ('Marseille', 'Moscow')), ('weather', 'cloudy'))]
  
  generate_csv(test)
  </code></pre>
  <p>The instructions for this example are:</p>
  <pre><code>Create a function generate_csv(a_list) that will create a csv file called results.csv.
  
  Your function will be called with a list of tuples (like in the following examples). 
  The tuples will contains tuples which contains as a first a key and as a second value the value
  associated with the key. The keys will always be the same. You must show this keys in 
  the first line of your csv. After this line you need to add the values formatted like this :
  
  a list or a tuple must be string: &quot;a,b,c&quot;
  a date must follow the US Standard: &quot;month/day/year&quot;
  You don't need to format the other values.
  
  Your csv must use ',' as separator and '&quot;' as quotechar.
  </code></pre>
  <p>How can I get rid of the newline between each line I write?
  What is the best way to format the tuples and the datetime so it matches the requested output?
  If I convert the output to str like this:</p>
  <pre><code>writer.writerow(str(j[1:]))
  </code></pre>
  <p>The output is a mess and becomes this:</p>
  <pre><code>(,4,2,&quot;,&quot;,)
  (,d,a,t,e,t,i,m,e,.,d,a,t,e,(,2,0,1,7,&quot;,&quot;, ,1,&quot;,&quot;, ,2,2,),&quot;,&quot;,)
  (,(,',B,e,r,l,i,n,',&quot;,&quot;, ,',P,a,r,i,s,',),&quot;,&quot;,)
  (,',s,u,n,n,y,',&quot;,&quot;,)
  (,-,4,2,&quot;,&quot;,)
  (,d,a,t,e,t,i,m,e,.,d,a,t,e,(,2,0,1,7,&quot;,&quot;, ,1,&quot;,&quot;, ,2,2,),&quot;,&quot;,)
  (,(,',M,a,r,s,e,i,l,l,e,',&quot;,&quot;, ,',M,o,s,c,o,w,',),&quot;,&quot;,)
  (,',c,l,o,u,d,y,',&quot;,&quot;,)
  </code></pre>