python - Extracting value from nested dictionary -


my dictionary this:

query =  {'fowl': [{'cateogry': 'space'}, {'cateogry': 'movie'}, {'cateogry': 'six'}], u'year of monkey': {'score': 40, 'match': [{'category': u'movie'}, {'category': 'heaven'}, {'category': 'released'}]}} 

fowl , year of monkey 2 entities in this. trying extract category values both entities separately no luck.

none of these work:

query[0] # expecting values fowl query[0]['category'] # expecting category fowl seems wrong query[0]['category'][0] # category space fowl 

what correct approach?

well, query dictionary rather funky, one, 'fowl' , 'year of monkey' values not structured same, cannot aply same data access patterns, or categories being misspelled 'cateogry'. if can, may better off fixing before trying process further.

as extracting 'fowl' data:

>>> query =  {'fowl': [{'cateogry': 'space'}, {'cateogry': 'movie'}, {'cateogry': 'six'}], u'year of monkey': {'score': 40, 'match': [{'category': u'movie'}, {'category': 'heaven'}, {'category': 'released'}]}}  >>> query['fowl'] # 'fowl' [{'cateogry': 'space'}, {'cateogry': 'movie'}, {'cateogry': 'six'}]  >>> [d['cateogry'] d in query['fowl']] # 'fowl' categories ['space', 'movie', 'six']  >>> [d['cateogry'] d in query['fowl']][0] # 'fowl' 'space' category 'space' 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -