Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

loop over dict python looking for match in list

list_of_dict = [{'a': 1, 'b': 5,
                 'c': 3,
                 'd': 6}, {'a': 3,
                           'f': 2,
                           'g': 1,
                           'h': 3,
                           'i': 5,
                           'j': 3}]

list_to_match = ['a', 'f', 'x']

d = {}
for match in list_to_match:
    for ld in list_of_dict:
        d.setdefault(match, []).append(ld.get(match, 0))

print(d)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #loop #dict #python #match #list
ADD COMMENT
Topic
Name
6+7 =