需要对不确定长度的字典和不确定个数的字典做相加操作,相同的key的value相加,
from collections import OrderedDict,Counter dict1 = {1:2,3:4} dict2 = {1:2,3:4,8:90} dict3 = {1:2,3:4,8:9,10:89} result = Counter({}) dict_list = [dict1,dict2,dict3]#这里字典随便搞 for dicts in dict_list: result= result +Counter(dicts) last_result = dict(result)
时间: 2024-10-11 13:37:11