When you assign a appendic
to two different keys, Python doesn't make a copy. It assigns a reference instead.
As a result, both dic['please_make_me_Foo']
and dic['dont_make_him_Bar']
refer to the same object. These are not separate dictionaries, they are both the same object, the one appendic
also references to.
If you expected these to be separate dictionaries, create a copy of appendic
instead. The dict.copy()
method creates a shallow copy of a dictionary:
dic['please_make_me_Foo']= appendic.copy()
dic['dont_make_him_Bar'] = appendic.copy()
Shallow means that a new dictionary is created and all references to keys and values contained are copied over.
If appendic
itself contains values that are also dictionaries, these would not be copied. The new copy and appendic
would both refer to the same values. In most cases, that's not a problem because most primitive values (strings, integers, etc.) are immutable, and you never notice references are shared as you replace such values with new ones.