defaultdict count key value pairs code example Example: defaultdict count key value pairs d = {'a': 1, 'b': 1, 'c': 3, 'd': 4} >>> sum(d.values())