Easiest to just use a Counter
>>> from collections import Counter
>>> a = dict(a=1,b=2 )
>>> b = dict( b=3,c=2)
>>> Counter(a)+Counter(b)
Counter({'b': 5, 'c': 2, 'a': 1})
>>> dict(Counter({'b': 5, 'c': 2, 'a': 1}))
{'a': 1, 'c': 2, 'b': 5}
More Related Contents:
- Adding a element in dictionary which consist of dictionaries.
- How do I merge two dictionaries in a single expression (take union of dictionaries)?
- Iterating over dictionaries using ‘for’ loops
- Delete an element from a dictionary
- How to merge multiple dicts with same key or different key?
- Rename a dictionary key
- Modifying a Python dict while iterating over it
- What’s a correct and good way to implement __hash__()?
- Safe method to get value of nested dictionary
- How to convert an XML string to a dictionary?
- How to sum dict elements
- How do I format a string using a dictionary in python-3.x?
- How to add multiple values to a dictionary key in python?
- Thread Safety in Python’s dictionary
- python filter list of dictionaries based on key value
- Extract subset of key-value pairs from dictionary?
- How does the key argument in python’s sorted function work?
- String to Dictionary in Python [duplicate]
- Convert a python dict to a string and back
- sort dict by value python [duplicate]
- filter items in a python dictionary where keys contain a specific string
- What does the == operator actually do on a Python dictionary?
- Callable as the default argument to dict.get without it being called if the key exists
- Adding counters deletes keys
- Using Dictionaries with numba njit function
- Python Pickling Dictionary EOFError
- Is the order of a Python dictionary guaranteed over iterations?
- Know the depth of a dictionary
- How can I make a list of dictionaries according to the Cartesian product of values in a source dictionary (“explode” the dictionary)?
- why dict objects are unhashable in python?