How do I write lists into CSV in python?
<p>I have the following list in Python. </p>

<pre><code>[('a1',
[('b', 1),
 ('c', 2),
 ('d', 3),
 ('e', 4),
 ('f', 5),
 ('g', 6]),

('a2',
[('c', 7),
 ('f', 8),
 ('g', 9),
 ('b', 1),
 ('e', 2),
 ('d', 3)])]
</code></pre>

<p>I would like to save the list as the following format in csv: </p>

<pre><code>a1      a2
b  1    c  7
c  2    f  8
d  3    g  9
e  4    b  1
f  5    e  2
g  6    d  3
</code></pre>

<p>This should get you started:</p>

<pre><code>&gt;&gt;&gt; a = [('b', 1), ('c', 2)]
&gt;&gt;&gt; b = [('c', 7), ('f', 8)]
&gt;&gt;&gt;
&gt;&gt;&gt; for x,y in zip(a,b):
...     k1, v1 = x
...     k2, v2 = y
...     print("{k1} {v1} {k2} {v2}".format(k1=k1, v1=v1, k2=k2, v2=v2))
...
b 1 c 7
c 2 f 8
</code></pre>

python csv