So I've found these two resources: Iterating over list of dictionaries and Nested dictionary comprehension python
but I'm new to python and am having trouble understanding nested structures within different structures (nested dictionaries within a list, or nested lists within a dictionary.
For instance, if I'm trying to get the dictionary within camera (so the key-item pairs of "color": "black", "res": 16 and then append that to a list.
Thanks much!
*updating below to append to a list.
nested_lst3 = [{"camera":{"color": "black", "res": 16}, "phone":1}, {"car":{"amount": 1, "year": 2017, "color": "red"}, "van":0}]
def get_values(d):
for i in d:
for key in d[i]:
l.append(key)
return(l)
#or this
def get_values(d):
for i in d:
for key, values in d[i]:
if type(values) is dict:
get_values(values)
else:
print(key, ":", value)
get_values(nested_lst3)