I'm not sure if I am going crazy here. I have numerical data stored in a dictionary which I will run a function to alter that data. Before I do this, I want to temporarily store the data to compare with the next iteration. In this example, dictionary
is the dictionary in question and update_data
is a function which manipulates the values of the object 'data'
in the dictionary.
example:
for i in range(n_iterations):
old_data = dictionary.get('data')
#call function which manipulates data
dictionary['data'] = update_data(dictionary)
diff = max(dictionary['data']-old_data)
when I compare the old and new, they are the same through each iteration. diff
is always 0
and when I compare them visually, it seems that when I set old_data
, I am implying a global link between the variable old_data
and the dictionary value.
Can someone please clarify the linkages between the dictionary object and the variable in the above example? Also, can someone suggest a workaround to storing the object before it is manipulated? Thank you