[Tutor] would someone please explain this concept to me
Steven D'Aprano
steve at pearwood.info
Tue Jun 4 21:14:54 EDT 2019
In case you are still confused, we can simplify the whole process by
eliminating the unnecessary use of an external module.
blank = {}
feeds = {}
feeds['a'] = blank
feeds['a'][1] = "Hello"
print(blank)
# will print {1: 'Hello'}
We can see that the dict named "blank" and the dict named "feeds['a']"
are actually the same dict:
print(feeds['a'] is blank) # Not the same as == (equals).
In case you still need more evidence:
feeds['b'] = blank
feeds['b'][1] = "Goodbye"
print(blank)
print(feeds)
will print:
{1: 'Goodbye'}
{'a': {1: 'Goodbye'}, 'b': {1: 'Goodbye'}}
(possibly the a and the b will be swapped around).
--
Steven
More information about the Tutor
mailing list