What is Nostr?
Glyph /
npub1h5u…y2g4
2024-06-16 20:05:10

Glyph on Nostr: This is possibly my least (most?) favorite #PythonOddity : ``` def loop(): for number ...

This is possibly my least (most?) favorite #PythonOddity :

```
def loop():
for number in range(10):
def closure():
return number
yield closure

eagerly = [each() for each in loop()]
lazily = [each() for each in list(loop())]
```

Understanding why `eagerly` and `lazily` differ is *crucial* to understanding how scopes work in Python, and illustrates a weakness in the otherwise pretty great “you don’t have to declare variables” structure of the language.
Author Public Key
npub1h5u94g9409m9c6yrckcwk9lg4c6sexyvvk23p0s7s3f42lhrs7zq75y2g4