Reputation: 11
I want to get dictionaries inside list and get specific values from them.
here is list that contain actual data:
[[{'confidence': 0.9655525279517, 'type': 'value', 'value': 'firefox'}],
[{'confidence': 0.97317936846366, 'type': 'value', 'value': 'open'}],
[{'confidence': 0.98969319754083, 'value': 'app'}]]
what i want is: get value from every dictionary like:
value :'firefox'
value : 'open'
value : 'app'
How i can accomplish this?
Upvotes: 0
Views: 47
Reputation: 227
Mylist = [[{'confidence': 0.9655525279517, 'type': 'value', 'value': 'firefox'}], [{'confidence': 0.97317936846366, 'type': 'value', 'value': 'open'}], [{'confidence': 0.98969319754083, 'value': 'app'}]]
for i in range(len(Mylist)):
Values = Mylist[i][0]['value']
print(Values)
in this way you can accomplish it
Upvotes: 1
Reputation: 26335
Just loop over each list, and extract what you need:
>>> lst = [[{'confidence': 0.9655525279517, 'type': 'value', 'value': 'firefox'}], [{'confidence': 0.97317936846366, 'type': 'value', 'value': 'open'}], [{'confidence': 0.98969319754083, 'value': 'app'}]]
>>> print([x[0]['value'] for x in lst])
['firefox', 'open', 'app']
Upvotes: 0