I'm new to Python and is confused by a piece of code in Python's official documentation.
unique_words = set(word for line in page for word in line.split())
To me, it looks equivalent to:
unique_words=set()
for word in line.split():
for line in page:
unique_words.add(word)
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.
Can anyone clarify the correct order for me?