insert into dictionary python for loop code example
Example 1: python generate dictionary in loop
n = int(input())
ans = {i : i*i for i in range(1,n+1)}
print(ans)
Example 2: python loop append to dictionary
case_list = []
for entry in entries_list:
case = {'key1': entry[0], 'key2': entry[1], 'key3':entry[2] }
case_list.append(case)