How to find a value in a list of dictionaries

Finding a value in a list of dictionaries returns the dictionaries that contain that value. For example, only the dictionary {“even”: 2, “odd”: 3} contains the value 3 in [{“even”: 0, “odd”: 1}, {“even”: 2, “odd”: 3}].

Solution for How to find a value in a list of dictionaries : You can use a for-loop to find a value in a list of dictionaries Use a for-loop to iterate through each dictionary in the list and check if it contains the sought value.

Use a list comprehension for a more compact implementation.

found_value = [dictionary for dictionary in list_of_dictionaries if dictionary["odd"] == 3]


how-to-find-a-value-in-a-list-of-dictionaries