def modify(a_dict):
alt_dict = a_dict.copy()
alt_dict['s'] = 2
a_dict = alt_dict
a_dictionary = {}
a_dictionary['f'] = 5
modify(a_dictionary)
print(a_dictionary)
The expected result is that a_dictionary will now also containt the key 's'. I know lists and dictionaries are passed by reference as mutables, but is there a way to update the reference within a function as I'm trying to do above?.. Or is there a better way?..
To clarify, I do indeed need to make a copy, because the changes I make in inside my actual function in code I might discard if an exception happens.