# list of dict keys
function_vars = ["x_reserve", "y_reserve", "wx", "wy", "decay_rate"]
# Initialize a dictionary with empty array values
stats = dict.fromkeys(function_vars, [])
for var in function_vars:
print(var)
stats[var].append(0)
stats
I initialized a dictionary using function_vars elements as dictionary values. Then I want to create a loop that updates each dictionary key once. However I am getting 5x as many values as I anticipated:
{'decay_rate': [0, 0, 0, 0, 0],
'wx': [0, 0, 0, 0, 0],
'wy': [0, 0, 0, 0, 0],
'x_reserve': [0, 0, 0, 0, 0],
'y_reserve': [0, 0, 0, 0, 0]}
but the output should be
{'decay_rate': [0],
'wx': [0],
'wy': [0],
'x_reserve': [0],
'y_reserve': [0]}
What is going on with my logic? I am not sure what I am missing and how to fix my (wrong) results