Python 3 changing value of dictionary key in for loop not working
问题 I have python 3 code that is not working as expected: def addFunc(x,y): print (x+y) def subABC(x,y,z): print (x-y-z) def doublePower(base,exp): print(2*base**exp) def RootFunc(inputDict): for k,v in inputDict.items(): if v[0]==1: d[k] = addFunc(*v[1:]) elif v[0] ==2: d[k] = subABC(*v[1:]) elif v[0]==3: d[k] = doublePower(*v[1:]) d={"s1_7":[1,5,2],"d1_6":[2,12,3,3],"e1_3200":[3,40,2],"s2_13":[1,6,7],"d2_30":[2,42,2,10]} RootFunc(d) #test to make sure key var assignment works print(d) I get: {