如何从python嵌套列表中的嵌套字典中提取值

时间:2019-04-28 19:28:30

标签: python python-3.x dictionary

以下是我的代码段。我试图从嵌套列表中的嵌套字典中提取'string'和'score'的值。我该怎么做?

预期输出为“对象元素”和“ 1.0”

[{'Form': [{'string': 'object element', 'score': 1.0,}],
  'types': ['http://google.com'],
'threshold':34}]

1 个答案:

答案 0 :(得分:3)

这应该有效

data = [{'Form': [{'string': 'object element', 'score': 1.0,}], 'types': ['http://google.com'], 'threshold':34},{'Form': [{'string': 'data store', 'score': 0.9,}], 'types': ['http://google.com'], 'threshold':23}]

for d in data:
    print(d['Form'][0]['string'])
    print(d['Form'][0]['score'])
相关问题