Every loop I'm calculating values of lists, outcomes are mostly wrong values. In trying to isolate the problem, I stumbled across something weird.
The changing of a value in a list
working_list[i] += value1
seems to have an effect on other lists.
"working_list" is a list that I need for further calculations, at the end of which I get "value2" which I use to adjust "result_list". I noticed, that result_list is not just changing in the last step of my calculation (at the end of the loop), but seems to change during the modification of the working_list. It makes me think I'm fundamentally misunderstanding how lists work.
A demonstration of the key lines (which to my understanding should be enough to see what my problem is):
result_list_empty=[]
for i in range(8760):
results_list_empty.append(0)
results_list=results_list_empty
for n in range(years)
working_list=results_list_empty
for i in range(len(working_list)):
print 'BEFORE '+str(sum(result_list))
working_list[i] += value1
print 'AFTER '+str(sum(result_list))
value2=some_calulation(working_list)
result_list[i]+=value2
returns
BEFORE 3.97469913304
AFTER 5.61311451171
To me this is confusing because code is supposed to work from top to bottom.. I'm not calling a function, just changing the value of a list member. So result_list changing doesn't make sense to me. Could somebody explain to me what's happening here?
Cheers