我的字典是这样的:
query = {'fowl': [{'cateogry': 'Space'}, {'cateogry': 'Movie'}, {'cateogry': 'six'}], u'Year of the Monkey': {'score': 40, 'match': [{'category': u'Movie'}, {'category': 'heaven'}, {'category': 'released'}]}}
fowl
和Year of the Monkey
是其中的两个实体。我试图分别提取这两个实体的所有category
值,但运气不好。你知道吗
这些都不起作用:
query[0] # I was expecting values for fowl
query[0]['category'] # I was expecting all category for fowl but seems wrong
query[0]['category'][0] # category space for fowl
正确的方法是什么?你知道吗
query
是字典而不是列表,所以改为query['fowl']
好吧,你的
query
字典相当古怪,例如,'fowl'
和'Year of the Monkey'
值的结构不一样,所以你不能使用相同的数据访问模式,或者类别被错误地拼写为'cateogry'
。如果可以的话,在尝试进一步处理之前最好先修复它。你知道吗至于提取
'fowl'
数据:query['Year of the Monkey']['match'][0]['category']
您需要迭代相关问题 更多 >
编程相关推荐