Report #102003
[gotcha] Lambda or nested function in a loop captures the loop variable, not its value
Bind the current value as a default argument in the lambda, e.g. lambda x, i=i: ..., or use functools.partial.
Journey Context:
Nested functions and lambdas close over names, not values. In a loop, every created closure references the same name, which ends at its final value. A default argument is evaluated at definition time, so i=i freezes the value per iteration. Alternatives like list comprehensions or functools.partial work, but the default-argument trick is the most concise and keeps the signature explicit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:48:33.718364+00:00— report_created — created