I have this script that sets up multiple different defaultdict
's within an ordinary dictionary
. However, the default values appear to be incorrect after setup. I would like to verify that this is indeed a bug:
from collections import defaultdict
labels = {1: 0, 2: 1, 3: 2, 4: 9000}
my_dict = {}
for label, value in labels.items():
my_dict[label] = defaultdict(lambda: value)
for tdx in range(2):
my_dict[label][tdx] = -1
line = "Bug at my_dict[1][-1]: {}".format(my_dict[1][-1])
print(line) # Prints 9000