I have a dictionary and I want to extract a value from the dictionary and hand it over to a variable. The problem is: when I give the value from the dictionary to the variable and add a value to the variable (in the way I did it in the following example) my Dictionary changes too.
But I don’t want to change the value of the variablekey in the dictionary.
dict=Dict{Any,Any}((0) => [1],(1) =>[2], (2) => [3],(3) => [4])
y = append!(dict[ ( 0 ) ], [1])
println("variable y is ", y)
print("dict should not change but it changed to: ", dict)
This behavior is more due to the nature of arrays than to the fact that they are in a Dict. Arrays are passed by reference. If you want a distinct storage area you should copy the array.