Put list into dict with first row header as keys
<p>I have the following python list:</p>

<pre><code>[['A,B,C,D'],
 ['1,2,3,4'],
 ['5,6,7,8']]
</code></pre>

<p>How can I put it into a dict and use the first sub list as the keys?:</p>

<pre><code>{'A': '1',
 'B': '2',
 'C': '3',
 'D': '4'}
{'A': '5',
 'B': '6',
 'C': '7',
 'D': '8'}
</code></pre>

<p>Thanks in advance!</p>

<p>Just use a <a href="https://docs.python.org/2/library/csv.html#csv.DictReader" rel="nofollow">DictReader</a> instance.  People usually use these with a file object, but actually it doesn't really care what you pass it as long as it can iterate the thing.</p>

<pre><code>&gt;&gt;&gt; L = [['A,B,C,D'],
...  ['1,2,3,4'],
...  ['5,6,7,8']]
&gt;&gt;&gt; import csv
&gt;&gt;&gt; reader = csv.DictReader((line for [line] in L))
&gt;&gt;&gt; d1, d2 = reader
&gt;&gt;&gt; d1
{'A': '1', 'B': '2', 'C': '3', 'D': '4'}
&gt;&gt;&gt; d2
{'A': '5', 'B': '6', 'C': '7', 'D': '8'}
</code></pre>

python