Write a program to merge a list of dictionaries into a single dictionary using dictionary comprehension


Topic: Write a program to merge a list of dictionaries into a single dictionary using dictionary comprehension

Solution

input = [{"foo": "bar", "Hello": "World"},
         {"key1": "val1", "key2": "val2"},
         {"sample_key": "sample_val"}]
merged_dict = {key: value for d in input for key, value in d.items()}



List all Python Programs