I am altering a state dictionary in a for loop and appending the new states to a list every iteration.
In Python, dictionaries are of course mutable so what gets appended to the list is a reference to the continuously mutating dictionary object. So at the end I just get a list of the same duplicated reference, pointing to the final version of the state.
state = {'temp': 21.6, 'wind': 44.0}
state_list = []
for i in range(10):
state['temp'] += 0.5
state['wind'] -= 0.5
state_list.append(state)
Is there a way to tell the interpreter that I wish to 'pass by value'? I am capable of constructing a tuple or something mutable from the state the line before the append, and appending the list with say tuples. I just want to check this is the best solution.