Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: django bring specific values first 
Python :: echo linux with ANSI escape sequence for change output color 
Python :: python dict setdefault list 
Python :: how to dynamically append value in a list in python 
Python :: install open3d jetson nano aarch64 
Python :: Window freezes after clicking of button in python GTK3 
Python :: sumy library 
Python :: how to store file into folder bucket aws 
Python :: tkinter trig calculator 
Python :: raise keyerror(key) from none os.environ 
Python :: downloading datasets from ml.org repository 
Python :: funtools rougly equivalent to, internal 
Python :: python save base64 temp file 
Python :: how to update sheety 
Python :: object creation using class constructor 
Python :: removeStopWords 
Python :: tusha 
Python :: python for skip header line 
Python :: convert json file to dict - if comming as list 
Python :: how to read json file from s3 bucket into aws glue job 
Python :: edit packet in scapy 
Python :: reset all weights tensorflow 
Python :: Select a Column in pandas data Frame Using Brackets 
Python :: sorting dictionary in python 
Python :: python loop increment by 2 
Python :: python read text on screen 
Python :: Creating a Tuple with Mixed Datatypes. 
Python :: Python Tkinter Menu Widget Syntax 
Python :: Adding a new nested object in the list using a Deep copy in Python 
Python :: program to print areas in python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =