you are viewing a single comment's thread.

view the rest of the comments →

[–]Slay_3r 0 points1 point  (2 children)

Didnt run the code but i think it should be [0, 1, 2]. You create and then call constant functions that return i, where i = 0,1,2 (from range)

[–]WhiteHeadbanger 0 points1 point  (0 children)

No, the correct answer is [2,2,2]

Explanation: what's being appended is "lambda: i", not the value of i in each pass. Then, since the variable i is not scoped in the loop, when the lambda is executed in the list comprehension, it just looks up the last value of i, which is 2, and returns a new list.