How can I rewrite this list comprehension as a for loop?
<p>How can I rewrite this using nested for loops instead of a list comprehension? </p>

<pre><code>final= [[]]  
    for i in array_list:
        final.extend([sublist + [i] for sublist in final])


    return final
</code></pre>

<p>If you try to iterate over final as you extend it, it creates an infinite loop. Because every time you go to the next element, you add another element, so you never reach the end of the list. </p>

<p>If you want to do the inner loop as a for loop instead of a list comprehension, you need to iterate over a copy of final. </p>

<pre><code>final = [[]] 
for i in [1, 2, 3]:
    for sublist in final[:]:
        final.extend([sublist + [i]]) 
</code></pre>

python