Thanks for taking your time to read my issue.
I have a coding scenario were I have an original dictionary. I set that original dictionary into a new variable, which from my understanding is spawning a clone of that object.
When I create a second dictionary, and use the update function of the new dict to merge the second dict, it updates the original dict and the new dict. I expect it to only update the new variable dict while perserving the original dict.
See a code example below:
dict1 = {"main": "test1"}
dict2 = {"sub": "test2"}
dict_combo = dict1
dict_combo.update(dict2)
print(dict1)
print(dict_combo)
Results:
$ python3 test_dict.py
{'main': 'test1', 'sub': 'test2'}
{'main': 'test1', 'sub': 'test2'}
What I expect to see:
$ python3 test_dict.py
{'main': 'test1'}
{'main': 'test1', 'sub': 'test2'}
As you can see, both dict1 and dict_combo are being updated when I am only updating the dict object called dict_combo.
Can someone explain why my expectation is wrong? Why is dict1 being updated?