The dictionary structure is:
storage = {}
storage['first'] = {}
storage['middle'] = {}
storage['last'] = {}
The first insertion made to this dictionary is:
me = 'Magnus Lie Hetland'
storage['first']['Magnus'] = [me]
storage['middle']['Lie'] = [me]
storage['last']['Hetland'] = [me]
Then the following statements are executed:
my_sister = 'Anne Lie Hetland'
storage['first'].setdefault('Anne', []).append(my_sister)
As per the documentation setdefault
should insert the key 'Anne'
with a value [] (New Empty list)
and then it should append my_sister
.
So why it is appending my_sister
to the pre-existing list and not creating new list.