title: The order of nested list comprehension and nested generator expression in python
body: <p>I'm new to Python and is confused by a piece of code in Python's official documentation.</p>
  
  <pre><code>unique_words = set(word  for line in page  for word in line.split())
  </code></pre>
  
  <p>To me, it looks equivalent to:</p>
  
  <pre><code>unique_words=set()
  for word in line.split():
      for line in page:
          unique_words.add(word)
  </code></pre>
  
  <p>How can line be used in the first loop before it's defined in the nested loop? However, it actually works. I think it suggests the order of nested list comprehension and generator expression is from left to right, which contradicts with my previous understanding.</p>
  
  <p>Can anyone clarify the correct order for me?</p>