I want to iteratively create a list of functions, with my desired result being phi = [lambda x: x+1, lambda x: x+2, lambda x: x+3]
. The code I have here creates the same function 3 times: phi = [lambda x: x+i, lambda x: x+i, lambda x: x+i]
, but I would like the functions to be independent of i
. How can I 'hard-code' the value of i
while looping?
Code I am using:
for i in range(3):
phi.append(lambda x: x + i)
The reason I want to do it this way is because I want 3 functions, rather than 1 that depends on i.