I´m having some trouble itering dictionaries within a list.
I have a list that looks like this:
mylist[0]
{'_id': ObjectId('aleatoryID'),
'created_at': datetime.datetime(2018, 3, 22, 11, 58, 23, 585000),
'person': {'id': '00115500',
'scores': {'SCORE_3': {'@score': '45'}, 'SCORE_1': 205, 'SCORE_2': 487}}}
Itering through SCORE_1 and SCORE_2 is fine, my problem is SCORE_3 since it contains a sub-sctructure within it. Here is my attempt:
persons = []
for document in mylist:
persons.append((document['person'].get('id'),
document['created_at'],
document['person']['scores'].get('SCORE_1'),
document['person']['scores'].get('SCORE_2'),
document['person']['scores']['SCORE_3'].get('@score')
))
KeyError: 'SCORE_3'
What is the correct way to iter the dictionary in this situation?