I've been trying to understand how name lookup works in python and have been messing with the global dictionary and stumbled upon something that confused me
>>> glob_dict=globals()
>>> glob_items=glob_dict.items()
>>> glob_list=list(glob_items)
>>> user_dict={'a':1,'b':2,'c':3}
>>> user_items=user_dict.items()
>>> user_list=list(user_items)
>>> user_dict['d']=4
>>> user_list
[('a', 1), ('b', 2), ('c', 3)]
>>> glob_list
... 'user_list': [('a', 1), ('b', 2), ('c', 3)]}), ('glob_items', ...), ('glob_list',
[...]), ('user_dict', {'a': 1, 'b': 2, 'c': 3, 'd': 4}), ('user_items', dict_items([('a',
1), ('b', 2), ('c', 3), ('d', 4)])), ('user_list', [('a', 1), ('b', 2), ('c', 3)])]))]
There were a lot of items in glob_list so I removed most for purposes of reading. Notice how in glob_list when an item is added in the global dictionary, it is updated in the list seen by the appearance of'user_list' or 'user_items' or any other values really when I tried updating it. In the user dictionary, the list remains the same though user_items is updated
dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4)])
What causes this difference? I also feel like I don't really understand dict_items very well so this may add to the confusion. I (think I) understand name binding rules and the difference between mutable and immutable types. At first I thought that glob_list was referencing the still stored glob_items which is mutable which was why it was updating. But then the same thing didn't occur for the user_list so I am thoroughly confused. Why is there a difference and what is going on?