title: convert list of dict to CSV string using dict_keys
body: <p>i am trying to convert a list of dict's to csv string for a lambda function.
  the code i have written below gives data as key value. i am trying to re-write this so that it works based on the dict_keys. </p>
  
  <pre><code>import io
  import csv
  
  output = io.StringIO()
  csvdata = [{"fruit": "apple", "count": "1", "color": "red"},{"fruit": "banana", "count": "2", "color": "yellow"}]
  writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC)
      for i in csvdata:
          for key, value in i.items():
              writer.writerow([key, value])
  convertedtocsv = output.getvalue()
  </code></pre>
  
  <p>output: '"fruit","apple"\r\n"count","1"\r\n"color","red"\r\n"fruit","banana"\r\n"count","2"\r\n"color","yellow"\r\n'</p>
  
  <pre><code>fruit  apple
  count  1 
  color  red
  fruit  banana
  count  2
  color  yellow
  </code></pre>
  
  <p>i would want the data in below format</p>
  
  <pre><code>fruit   count  color
  apple   1      red
  banana  2      yellow
  </code></pre>
  
  <p>i am aware that this can be achieved in pandas using the .to_csv method. but i just wanted to try it without pandas or any 3rd party libraries.</p>
  
  <p>any help is appreciated. thanks!</p>