title: Arranging keys and values from a dictionary in a csv file - Python
body: <p>I have a dictionary that looks like this:</p>
  
  <pre><code>dictionary = {'Alice': ['10', '10'], 'Tom': ['9', '8'], 'Ben': ['10', '9']}
  </code></pre>
  
  <p>I have created a csv file using this dictionary by using the following code which I have taken &amp; adapted from a previous post (<a href="https://stackoverflow.com/questions/10373247/how-do-i-write-a-python-dictionary-to-a-csv-file">How do I write a Python dictionary to a csv file?</a>):</p>
  
  <pre><code>with open('test.csv', 'w') as file:  
  writer = csv.DictWriter(file, dictionary.keys(), lineterminator="\n")
  writer.writeheader()
  writer.writerow(dictionary)
  </code></pre>
  
  <p>This creates a csv file that looks like this:</p>
  
  <pre><code>Alice, Tom, Ben 
  ['10', '10'], ['9', '8'], ['10', '9']
  </code></pre>
  
  <p>But I would like to create a csv file that looks like this:</p>
  
  <pre><code>Alice, ['10', '10']
  Tom, ['9', '8']
  Ben, ['10', '9']
  </code></pre>