Index of each element within list of lists
<p>I have something like the following list of lists:</p>

<pre><code>&gt;&gt;&gt; mylist=[['A','B','C'],['D','E'],['F','G','H']]
</code></pre>

<p>I want to construct a new list of lists where each element is a tuple where the first value indicates the index of that item within its sublist, and the second value is the original value.</p>

<p>I can obtain this using the following code:</p>

<pre><code>&gt;&gt;&gt; final_list=[]
&gt;&gt;&gt; for sublist in mylist:
...     slist=[]
...     for i,element in enumerate(sublist):
...         slist.append((i,element))
...     final_list.append(slist)
... 
&gt;&gt;&gt; 
&gt;&gt;&gt; final_list
[[(0, 'A'), (1, 'B'), (2, 'C')], [(0, 'D'), (1, 'E')], [(0, 'F'), (1, 'G'), (2, 'H')]]
&gt;&gt;&gt; 
</code></pre>

<p>Is there a better or more concise way to do this using list comprehension?</p>

<pre><code>final_list = [list(enumerate(l)) for l in mylist]
</code></pre>

python list