I want to assign a value from a dictionary into another but when I do that it seems to point to the original dictionary and both get changed when I make modifications. Note I only want certain values so I cannot just copy the whole dictionary (unless I am mistaken).
Originaldic = {"Foo":["Somthing",1], "Bar":["action",2], "baz":["otherthing",6]}
listofplayer = ["Bar","Foo"]
Tempdic = {}
for player in listofplayer:
Tempdic[player]=Originaldic[player]
#the problem is likely at this step above
if Tempdic[player][1]==2:
Tempdic[player].pop(0)
#note: I have to use pop here because in reality I have a list of list but tried simplify the code
Tempdic[player] = ["differentaction",5]
print(Tempdic)
#{'Bar': ['differentaction', 5], 'Foo': ['Somthing', 1]}
print(Originaldic)
#{'Foo': ['Somthing', 1], 'Bar': [2], 'baz': ['otherthing', 6]}
what I do not understand is why the original dictionary had been modified too. I know you cannot just do dic1 = dic2 but I assumed (wrongly) I was dealing with values of the dictionary here not pointing at the value in a dictionary: 'Bar': [2] instead of "Bar":["action",2] it seem to have done Originaldic["Bar"].pop(0) as well.
EDIT: thank you to Mady for providing an answer, here the issue was not copying two dic like I thought but copying the list that was held in the dictionary (which caused a very similar issue).