比如说有两个dict:x和y
1.比较快的自己写的,
def merge_dict(x,y):
for k,v in x.items():
if k in y.keys():
buffer[k] += v
else:
buffer[k] = v
2.调用api,这个慢一点
from collections import Counter
X,Y=Counter(x),Counter(y)
z=dict(X+Y)