how to create a for loop for this case in python?
<p>maybe the title seems strange, but i'm bloqued for certain times searching how to create a for loop of this case:</p>

<p>I have a list of lists having this format :</p>

<pre><code> data=[['nature', author1, author2, ...author n]
       ['sport', author1, author2, ....author n]
       ....
      ]
</code></pre>

<p>I have tried this code :</p>

<pre><code>        authors=[author1, author2, ...author n]
         for i in range(len(authors)):

        data = [['nature', function(names[i], 'nature')],
                ['sport', function(names[i], 'sport')
             ..]
</code></pre>

<p>but unfortunately I guess it returns a result in this format :</p>

<pre><code> data=[['nature', author1]
       ['sport', author1]
       ....
      ]
</code></pre>

<p>Convert it to a dictionary, and then iterate over the key pairs</p>

<pre><code>data = [['foo', 1, 2, 3], ['bar', 2,3,4]]
dat = {i[0]: i[1:] for i in data }        
for k, v in dat.items():
    print("{0}: {1}".format(k, v))


Output
bar: [2, 3, 4]
foo: [1, 2, 3]
</code></pre>

<p>except.... <em>dont do this</em>.</p>

<p>I'm merely showing this to show that your data should be in a dictionary in the first place.</p>

python django for-loop