What is the correct fix?
callbacks = [lambda: i for i in range(3)] print(callbacks[0]())
- Bind
ias a default argument - Wrap each lambda in
tuple() - Replace the lambda with
def - Iterate over
list(range(3))
The lambdas close over
Play Problem Solving ▸
i itself, so all three see its final value.