Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python filter list of dictionaries by value

dict_list = [{'a': 1, 'b': 2}, {'b': 1, 'c': 2}, {'c': 1, 'd': 2}]
filter_value = 2

[{k:v for k,v in d.items() if v == filter_value} for d in dict_list]
 
PREVIOUS NEXT
Tagged: #python #filter #list #dictionaries
ADD COMMENT
Topic
Name
5+5 =