jitendra sonawane
jitendra sonawane

Reputation: 11

How to get dictionary inside list and retrive specific values

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

Answers (2)

Ahmad
Ahmad

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

RoadRunner
RoadRunner

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

Related Questions