(For Python2Python 2.7* only; there are simpler solutions for Python3*Python 3*.)
If you're not averse to importing a standard library module, you can do
from functools import reduce
def merge_dicts(*dicts):
return reduce(lambda a, d: a.update(d) or a, dicts, {})
(The or a
bit in the lambda
is necessary because dict.update
always returns None
on success.)