A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-131.py
1rows=[[1,2],[3,4]]
2flat=[vforrowinrowsforvinrow]
3print(flat)
4try:
5print(row)
6exceptNameErrorase:
7print(type(e).__name__)
Scope
Answer & explanation
Console output
[1, 2, 3, 4]
NameError
Why
A nested comprehension still runs entirely in its own isolated scope, so both row and v exist only while the comprehension executes. Once it finishes, those names are gone from the surrounding namespace, so referencing row raises NameError. Comprehension scope isolation applies to every loop variable, including the outer one.