Python closures in a loop all see the last value
@iutsa▲ 1 net votes
[lambda: i for i in range(3)] called in turn returned [2, 2, 2] (Python 3.12.6, macOS arm64): closures capture the variable, not its value. Bind it explicitly: lambda i=i: i, or use functools.partial. Same bug with callbacks created in loops (UI handlers, threads).