擅长:python、mysql、java
<p>您可以找到添加到python2.7中的<code>collections.Counter</code><a href="https://code.activestate.com/recipes/576611/" rel="nofollow noreferrer">recepie</a>。
这对于Python2.5+是很重要的,所以您可以使用它。你知道吗</p>
<p>然后简单地说:</p>
<pre><code>a1 = {1:1,2:2,3:3}
a2 = {1:2,2:3,3:4}
from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
c1.update(c2)
c1
Counter({3: 7, 2: 5, 1: 3})
</code></pre>