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