Use collection.Counter() objects instead or convert dictionaries:
from collections import Counter result = Counter() for d in dicts: result |= Counter(d)
or even:
from collections import Counter from operator import or_ result = reduce(or_, map(Counter, dicts), Counter())
Counter objects support the search for the maximum value for each key due to operation | ; & gives you a minimum.
Demo:
>>> result = Counter() >>> for d in dicts: ... result |= Counter(d) ... >>> result Counter({'a': 11, 'c': 10, 'b': 7})
or using the reduce() version:
>>> reduce(or_, map(Counter, dicts), Counter()) Counter({'a': 11, 'c': 10, 'b': 7})
source share