Write dictionary to csv with one line per value
<p>I am quite new to Python so please excuse me if this is a really basic question. I have a Python dictionary such as this one:</p>

<p><code>foo = {'bar1':['a','b','c'], 'bar2':['d','e']}</code></p>

<p>I would like to write it to a csv file, with one line per <strong>value</strong> and the key as first element of each row. The output would be (whatever the quotation marks):</p>

<pre><code>bar1,'a'
bar1,'b'
bar1,'c'
bar2,'d'
bar2,'e'
</code></pre>

<p>I have tried this <a href="https://stackoverflow.com/questions/8685809/python-writing-a-dictionary-to-a-csv-file-with-one-line-for-every-key-value">such as suggested here</a></p>

<pre><code>import csv
with open('blah.csv', 'wb') as csv_file:
    writer = csv.writer(csv_file)
    for key, value in foo.items():
       writer.writerow([key, value])
</code></pre>

<p>but this gives the following output, with one line per <strong>key</strong>:</p>

<pre><code>bar1,"['a', 'b', 'c']"
bar2,"['d', 'e']"
</code></pre>

<p>Thanks for your help!</p>