I am trying to create a list of dictionaries, but everytime when I try to append a new item to the list, it is replacing the previous copies with then new item.
nested_dict = {}
request_data = {
"locale": "US",
"field": "Company Name",
"document_type": "invoice"
}
for key, value in request_data.items():
term_item = {}
term_item[key] = value
nested_dict["term"] = term_item
term_list.append(nested_dict)
Result obtained:
[{'term': {'document_type': 'invoice'}}, {'term': {'document_type': 'invoice'}}, {'term': {'document_type': 'invoice'}}]
Expectation :
[{'term': {"locale": "US"}}, {'term': {"field": 'Company Name'}}, {'term': {'document_type': 'invoice'}}]