4 ms·
Thanks, I didn't realize that. That makes their choice really baffling.
by pdw 6y ago
Thanks, I didn't realize that. That makes their choice really baffling.
- _nosewings_ 6y agoThe explanation is that (in Python 3) list comprehensions are really just syntactic sugar for generator expressions. In Python, "scope" is really a synonym for "dictionary attached to some object", so generators can have local variables (since they have their own internal scope), but purely syntactic constructs cannot.