I've found several SO posts on similar questions but I'm maybe overthinking my problem.
I'm running a loop. Each iteration returns a dict with the same keys and their own values. I'd like to combine them into a new master dict.
On each loop iteration I can save the results to a list
store_response = [] # will store the results of each iteration here
myloop:
code here...
store_response.append(iresponse.copy())
Or I can do:
store_response = {} # will store the results of each iteration here
myloop:
code here...
store_response[page_token] = iresponse # store this iteration and call it whatever string page_token currently is
So I can return either a list of dicts or dict of dicts.
My question is, how can I combine them into just one dict? Tried several for loops but keep hitting errors e.g.:
for d in store_response:
for key, value in d.iteritems():
test[key].append(value)
Traceback (most recent call last):
File "<input>", line 2, in <module>
AttributeError: 'dict' object has no attribute 'iteritems'
Here is how the variable looks in PyCharms variables pane, currently in list form but I could make it a dict:
How can I take each dict within store response and create a single master dict?