Given a list of runs up to a maximum reached stage, I would like to transfer the maximum values to a nested dictionary holding the number of tries (t) for each stage.
This means runs of 3, 4 and 7 should yield:
{0: {'t': 3}, 1: {'t': 3}, 2: {'t': 3}, 3: {'t': 2}, 4: {'t': 1}, 5: {'t': 1}, 6: {'t': 1}}
Stages 0,1,2 has been played for 3 times each, stage 3 for 2 times and stages 4, 5 and 6 only once.
I Get instead the following result:
{0: {'t': 14}, 1: {'t': 14}, 2: {'t': 14}, 3: {'t': 14}, 4: {'t': 14}, 5: {'t': 14}, 6: {'t': 14}}
Source Code
p = {}
p = dict.fromkeys(range(7), {})
runs = (3, 4, 7)
for r in runs:
for l in range(r):
if "t" in p[l]:
p[l]["t"] += 1
else:
p[l]["t"] = 1
Why are the values the same in all the dictionary's key?