I am writing a simple function and I want to iteratively run it so that it gets fed its own output, performs some operations and continues to do so until a certain number of times.
I have tried the following:
def optimize(lst):
A = lst[0]
B = lst[1]
C = lst[2]
# perform some operation, for example,
A = A+1
B = B+1
C = C+1
new_lst = [A,B,C]
lst[:] = new_lst # this overwrites the original param with the new output
print(new_lst)
return(new_lst)
for i in range(3):
optimize([1,2,3])
This just repeats for three times with the same input, i.e., 1,2,3 and prints [2,3,4]. It's not getting updated in each iteration. I mean it should take [2,3,4] and spit out [3,4,5] and so on. I know I am missing a very simple concept here. Kindly help. Thank you!
Note: The operations in my function is much more complicated. I chose to oversimplify it for representation purpose.