i have to create a list of functions, each pretty similar, but with a different constant.
for instance i want to have a list like "multiplication"
and i need hundreds of functions, so i used a for, the problem is that the functions that i have create multiply by the current value of "i", and not by the value that "i" had when the function has been declared
how do i get the desired result (like the firs list of function for instance)?
def main():
#method one (working)
multiplication = []
multiplication.append(lambda z:z*0)
multiplication.append(lambda z:z*1)
multiplication.append(lambda z:z*2)
multiplication.append(lambda z:z*3)
# moltiplication: 2*4
print(multiplication[2](4))
#output: 8
#method two (not working)
multiplication_2 = []
for i in range(4):
multiplication_2.append(lambda z:z*i)
#supposed to multiply 2*4 but multiply 4*i instead
print(multiplication_2[2](4))
#output: 12
i = 22
print(multiplication_2[2](4))
#output: 88
if (__name__ == '__main__'):
main()
i know that i can pass an argument to the function, but this is only an example that can lead me to solve my problem. and in the real use case the functions need to be created like this