This works for dictionaries of any length:
>>> result = {}
>>> for d in L:
... result.update(d)
...
>>> result
{'a':1,'c':1,'b':2,'d':2}
As a comprehension:
# Python >= 2.7
{k: v for d in L for k, v in d.items()}
# Python < 2.7
dict(pair for d in L for pair in d.items())
More Related Contents:
- How do I convert two lists into a dictionary?
- Convert [key1,val1,key2,val2] to a dict?
- Why can’t I use a list as a dict key in python?
- Remove duplicate dict in list in Python
- Grouping Python dictionary keys as a list and create a new dictionary with this list as a value
- Getting a list of values from a list of dicts
- How do I initialize a dictionary of empty lists in Python?
- Pandas DataFrame to List of Dictionaries
- Creating a list of dictionaries results in a list of copies of the same dictionary
- How can I make a dictionary from separate lists of keys and values?
- How to convert list of key-value tuples into dictionary?
- join two lists of dictionaries on a single key
- Check if value already exists within list of dictionaries?
- Convert list into a dictionary [duplicate]
- Combining Dictionaries Of Lists In Python
- Most Pythonic Way to Build Dictionary From Single List
- Python: get a dict from a list based on something inside the dict
- Make dictionary from list with python [duplicate]
- how to convert list of dict to dict
- How do I return dictionary keys as a list in Python?
- Why can’t I use a list as a dict key in python? Exactly what can and cannot be used, and why?
- convert csv file to list of dictionaries
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Getting the difference (delta) between two lists of dictionaries
- Python: iterating over list vs over dict items efficiency
- How can I convert string values from a dictionary, into int/float datatypes?
- Python Accessing Values in A List of Dictionaries
- How do I send list of dictionary as Body parameter together with Files in FastAPI?
- How to convert only numbers in a mixed list into float
- In what case would I use a tuple as a dictionary key? [closed]