python - Setting containers within a loop -


this question has answer here:

dicta = {'a':1, 'b':2, 'c':3} prea = {} print hex(id(prea)) preb = {} print hex(id(preb)) dicts = [prea, preb]         #<---- looks can't save this?  d in dicts:     print hex(id(d))     d = dicta print prea print preb 

output:

0x13348b0 0x13357f0 0x13348b0 0x13357f0 {} {} 

looks has same memory address when set prea or preb via variable 'd' , getting value prea or preb, it's if never set.

can explain whats going on here?

d set current dictionary @ iteration of each loop. setting d = dicta pointless because d change next dictionary first step.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -