Skip to content
Advertisement

Python – Pull Out Values from Only Dictionaries that Meet a Certain Criteria

I have a Python list called “results” that has dictionaries as its values:

JavaScript

How would I create a list that gets all the values from the dictionary where the ‘boardID’ value is ‘_internal’ (but ignores the dictionary where ‘boardID’ is ‘_external’)? As an end result, I’m hoping for a list with the following contents:

JavaScript

Advertisement

Answer

You can use list-comprehension:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement