Custom list of lists into dictionary
<p>I have list of lists and I wish to create a dictionary with length of each element as values. I tried the following:</p>

<pre><code>tmp = [['A', 'B', 'E'], ['B', 'E', 'F'], ['A', 'G']]
tab = []
for line in tmp:
    tab.append(dict((k, len(tmp)) for k in line))
</code></pre>

<p>But it gives the output as:</p>

<pre><code>[{'A': 3, 'B': 3, 'E': 3}, {'B': 3, 'E': 3, 'F': 3}, {'A': 3, 'G': 3}]
</code></pre>

<p>What is the modification that I should make to get the output:</p>

<pre><code>{['A', 'B', 'E']:3, ['B', 'E', 'F']:3, ['A', 'G']:2}
</code></pre>

<p>Thanks in advance.</p>

<p>AP</p>

<pre><code>{tuple(t):len(t) for t in tmp}
</code></pre>

<p>Input : </p>

<pre><code>[['A', 'B', 'E'], ['B', 'E', 'F'], ['A', 'G']]
</code></pre>

<p>Output :</p>

<pre><code>{('A', 'G'): 2, ('A', 'B', 'E'): 3, ('B', 'E', 'F'): 3}
</code></pre>

<p>Dictionnary does not accept list as key, but tuple</p>

python python-2.7 dictionary