I've reviewed many questions in StackOverflow that may be related to my question Q1, Q2, Q3, Q4 None of them are related to my question. Apart from these, I examined almost 20 questions here.
I created a sample code block to explain my problem simply. My aim is to add data to a dictionary in for loop.
When I run the code block below, the output is as follows.
dictionary = defaultdict(int)
for uid in range(10):
for i in range(5):
distance = 2*i
dictionary[uid] = distance
My aim is to keep the key value in each loop and add on it.
Expected Output:
{0: {0,2,4,6,8,}, 1:{0,2,4,6,8,}, 2:{0,2,4,6,8} , ...
My Solution
from collections import defaultdict
dictionary = defaultdict(int)
for uid in range(10):
for i in range(5):
distance = 2*i
dictionary[uid].append(distance)
My solution approach is also not working there is a problem