Я хочу вставить два словаря в список через цикл for. Я не понимаю, почему это не работает. Не могли бы вы помочь? :)
result = {}
results = []
for i in range(count): # Count is 2, 2 different dictionaries
result.update({
'workitem_id': str(api_results[i]['workitem_id']),
'workitem_header': api_results[i]['workitem_header'],
'workitem_desc': api_results[i]['workitem_desc'],
'workitem_duration': str(api_results[i]['workitem_duration'])})
print(result) # Shows the two different dictionaries
results.append(result)
print(results) # Shows the list of two dictionaries, but the list contains the last dictionary for 2 times.
Output print(result): {Dictionary 1} , {Dictionary 2}
Output print(results): [{Dictionary 2} , {Dictionary 2}]
Ожидаемый результат печати (результаты):
[{Dictionary 1}, {Dictionary 2}]