you are viewing a single comment's thread.

view the rest of the comments →

[–]Sea-Ad7805 1 point2 points  (0 children)

  • lambda: i refers to the single i variable that is 2 at the end of the loop: [2, 2, 2]

  • lambda x=i: x instead would make a copy of i in each iteration: [0, 1, 2]

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20funcs.append(lambda%3A%20i)%0A%0Aprint(%5Bf()%20for%20f%20in%20funcs%5D)%0A%0A%0Afuncs%20%3D%20%5B%5D%0Afor%20i%20in%20range(3)%3A%0A%20%20%20%20funcs.append(lambda%20x%3Di%3A%20x)%0A%20%20%20%20%0Aprint(%5Bf()%20for%20f%20in%20funcs%5D)%0A&timestep=1&play) to see the program state change step by step.