您可以使用collections.Countercounter = collections.Counter()for d in dict1: counter.update(d)或者,如果您更喜欢单线:functools.reduce(operator.add, map(collections.Counter, dict1))
sum()当添加多个命令时,利用杠杆应该可以获得更好的性能>>> dict1 = [{'a':2, 'b':3},{'a':3, 'b':4}]>>> from operator import itemgetter>>> {k:sum(map(itemgetter(k), dict1)) for k in dict1[0]} # Python2.7+{'a': 5, 'b': 7}>>> dict((k,sum(map(itemgetter(k), dict1))) for k in dict1[0]) # Python2.6{'a': 5, 'b': 7}加上斯蒂芬的建议>>> {k: sum(d[k] for d in dict1) for k in dict1[0]} # Python2.7+{'a': 5, 'b': 7}>>> dict((k, sum(d[k] for d in dict1)) for k in dict1[0]) # Python2.6{'a': 5, 'b': 7}我认为Stephan的Python2.7代码版本读起来非常好