Saturday, 2 September 2017

Lists as values in a dictionary Python

ddic = {'a': 10,'b': 23,'c': [0, 1, 2]}
n2 = ddic['c']
n2[-2] = 1000.

ddic
{'a': 10, 'b': 23, 'c': [0, 1000.0, 2]}



Why changing the list at which n2 is pointing, changes also the list of dict ddic, which is contained into the hash table that ddic defines?



It looks like that when you define a dict, the key-value pairs pops-in the global namespace and is not contained into the namespace defined by the hash-table structure.



Someone knows the detailed reason of this?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...