Python list of lists conversion into dictionary
<p>I'm trying to convert a list of lists into dictionary, but I'm getting troubles. Would anyone give some tips ?</p>

<p>This my input:</p>

<pre><code>[['Column1', 'Column2', 'Column3', 'Column4', 'Column5'],     
['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4',   
'Value1Column5'], ['Value2Column1', 'Value2Column2', 'Value2Column3', 
'Value2Column4', 'Value2Column5'], ..., 
['ValueXColumn1','ValueXColumn2', 'ValueXColumn3', 'ValueXColumn4', 'ValueXColumn5']]
</code></pre>

<p>Having this I would like to create a dictionary, where my keys would be <strong>only</strong> elements from 1st list which are <strong>Column1, Column2...Column5</strong>. </p>

<p>It's also known that for each key exact value is element from the rest of lists: </p>

<p>Column1 --> Value1Column1, Value2Column1...</p>

<p>Column2 --> Value1Column2, Value2Column2...</p>

<p><strong>Expected result:<br></strong></p>

<pre><code>"Column1": ["Value1Column1", "Value2Column1"...]
</code></pre>

<p>I've been trying with zip, enumurate (maybe wrongly used) and got always unexpected output. Thanks!</p>

<p>It's really simple with <a href="http://stackoverflow.com/questions/1747817/create-a-dictionary-with-list-comprehension-in-python">dict comprehension</a> and <a href="https://docs.python.org/3.5/library/functions.html#zip" rel="nofollow">zip function</a>.</p>

<pre><code>seq_of_seq = [['Column1', 'Column2', 'Column3', 'Column4', 'Column5'],
              ['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4', 'Value1Column5'],
              ['Value2Column1', 'Value2Column2', 'Value2Column3', 'Value2Column4', 'Value2Column5'],
              ['ValueXColumn1', 'ValueXColumn2', 'ValueXColumn3', 'ValueXColumn4', 'ValueXColumn5']]

d = {s[0]: s[1:] for s in zip(*seq_of_seq)}
</code></pre>

<p>This yields values as tuples:</p>

<pre><code>{'Column1': ('Value1Column1', 'Value2Column1', 'ValueXColumn1'),
 'Column2': ('Value1Column2', 'Value2Column2', 'ValueXColumn2'),
 'Column3': ('Value1Column3', 'Value2Column3', 'ValueXColumn3'),
 'Column4': ('Value1Column4', 'Value2Column4', 'ValueXColumn4'),
 'Column5': ('Value1Column5', 'Value2Column5', 'ValueXColumn5')}
</code></pre>

<p>If you really need lists use:</p>

<pre><code>d = {s[0]: list(s[1:]) for s in zip(*seq_of_seq)}
</code></pre>

<p>Result: </p>

<pre><code>{'Column1': ['Value1Column1', 'Value2Column1', 'ValueXColumn1'],
 'Column2': ['Value1Column2', 'Value2Column2', 'ValueXColumn2'],
 'Column3': ['Value1Column3', 'Value2Column3', 'ValueXColumn3'],
 'Column4': ['Value1Column4', 'Value2Column4', 'ValueXColumn4'],
 'Column5': ['Value1Column5', 'Value2Column5', 'ValueXColumn5']}
</code></pre>

python dictionary data-type-conversion