In here:
for entry in my_dict_1.keys():
my_dict_1[entry] = metric
You are assigning the value of metric
to all your dict
(my_dict_1
) items. Reason why ‘it just adds the last arg passed’.
Without cleaning up your code, here’s the patch to fix your issue:
for i, metric in enumerate(my_metrics):
...
my_dict_1[i] = metric
4
solved Python create nested dict in for loop [closed]