I am trying to understand a strange thing in Python. I created a dictionary in Python, assigned the dictionary values to a temporary variable, and then cleared all the values in the temporary variable. Strangely, the values in the dictionary also got cleared. What could be the reason behind it ?
For example, in cases where I do not want to affect the main variable, and just do something in the temporary variable, this will never work. Is there a workaround ?
Below is the steps that I tried to execute
dict = {'random' : [1, 2, 3, 4, 5]}
data = dict['random']
data
[1, 2, 3, 4, 5]
data.clear()
dict
{'random': []}