for this list:
current_trace = [[3,5,1,5,7,9,4]]
I run the sliding_tristep()
method, which includes the predict()
and window()
methods:
def predict(lst):
print "predicting for", lst
print "result", max(lst) + 0.0
return max(lst) + 0.0
def window(lst, n=3):
for x in range(1, len(lst)+1): # or len(l)+n to continue till the end
yield(lst[max(0, x-n):x])
def sliding_tristep(full_trace, future_step = 2, window_size = 3):
for user_trace in full_trace:
for current_input in window(user_trace):
counter = 0
trace = current_input
accumulator = []
while counter <= future_step:
next_prediction = predict(trace)
trace.append(next_prediction)
accumulator.append(next_prediction)
trace = trace[-window_size:]
counter += 1
print current_input, accumulator
When I run sliding_tristep(current_trace)
, in the output for the print current_input, accumulator
line I notice that the current_input
has been modified although it is out of the while loop which makes the calculations in sliding_tristep(current_trace)
.
I wonder why does this happen? How is that possible for python to modify a list which is not used at all in the subsequent loop.