title: NameError in Python Nested for loops of List Comprehension
body: <p><strong>Scenerio:</strong></p>
  
  <pre><code>for i in range(6):
      for j in range(i):
          j
  </code></pre>
  
  <p>AFAIK, in list comprehension the right most <code>for</code> is the outer one so, I thought the following code will work:</p>
  
  <pre><code>[ j for j in range(i) for i in range(6)]
  </code></pre>
  
  <p>But to my surprise, it throws a <code>NameError</code></p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'i' is not defined
  </code></pre>
  
  <p>I wonder why it didn't work. Is it because python evaluates expression from <em>Left to Right</em>? 
  Cause, I have resolved the issue by using parenthesis:</p>
  
  <pre><code>[ (j for j in range(i)) for i in range(6)]
  </code></pre>
  
  <p>which outputs a bunch of generator expressions:</p>
  
  <pre><code>[&lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200d00&gt;, &lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200d58&gt;, &lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200db0&gt;, &lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200e08&gt;, &lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200e60&gt;, &lt;generator object &lt;listcomp&gt;.&lt;genexpr&gt; at 0x7f3b42200eb8&gt;]
  </code></pre>
  
  <p>To explore what is inside these generator expressions we can simply cast them into lists i.e.</p>
  
  <pre><code>[ list(j for j in range(i )) for i in range(6)]
  </code></pre>
  
  <p>and the output is as expected:</p>
  
  <pre><code>[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]]
  </code></pre>
  
  <p>I just want to know what is really happening here. </p>