I am writing a script which builds a dictionary, and I observe a strange behaviour.
I will describe it below with a small example.
def test_f(parameter):
parameter.update({'watermelon':'22'})
return parameter
fruits = {'apple':20, 'orange': 35, 'guava': 12}
new_fruits = test_f(fruits)
In short, I have a dictionary which I pass to a function, test_f
. The function appends a new dictionary to the input and returns it. I capture the output of the function in a variable called new_fruits
. This however changes the original variable fruits
too.
Why does the original variable fruits
changes?
Am I using the update
method in an incorrect way?