How to search value by using key from list of dictionaries

list_of_dicts = [
{‘name’: ‘Alice’, ‘age’: 30},
{‘height’: 5, ‘weight’: 25},
{‘nickname’: ‘Charlie’}
]

from this mentioned list how to verify if particular key have particular value

You can use collections.ChainMap to create a consolidated mapping view to the underlying list of dicts:

from collections import ChainMap

list_of_dicts = [
    {'name': 'Alice', 'age': 30},
    {'height': 5, 'weight': 25},
    {'nickname': 'Charlie'}
]

person = ChainMap(*list_of_dicts)
assert person['height'] == 5 # passes
1 Like