I have a list containing values that should be used as keys for a dictionary. Right now the list to be converted to keys looks like the following:
myList = ["A", "B"]
I am converting this list to be the keys to a dictionary by doing the following:
newDict = dict.fromkeys(myList, {"Min":[], "Max":[], "Avg":[]})
When printing newDict I get the output:
{'A': {'Min': [], 'Max': [], 'Avg': []}, 'B': {'Min': [], 'Max': [], 'Avg': []}}
However, when trying to write to the newDict["B"]["Avg"]
list, the value gets added to both the "A"
and "B"
keys:
Code:
newDict["B"]["Avg"].append(111)
Output:
{'A': {'Min': [], 'Max': [], 'Avg': [111]}, 'B': {'Min': [], 'Max': [], 'Avg': [111]}}
Is there for the appended value to only be added to the intended key?