Every line of 'how to add two dictionaries in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
615 def addDict(base_dict,new_dict): 616 for k in new_dict.keys(): 617 new_el=new_dict[k] 618 if not base_dict.has_key(k): 619 # nothing there?, just copy 620 base_dict[k]=new_el 621 else: 622 if type(new_el)==type({}): #another dictionary, recourse 623 addDict(base_dict[k],new_el) 624 else: 625 base_dict[k]+=new_el
77 def combine_dicts(dict1, dict2): 78 return dict(dict1.items() + dict2.items())
63 def add_dicts_ext(add_func=lambda a, b: a+b, zero=0): 64 def add_dicts(*dicts): 65 res = {} 66 for d in dicts: 67 for k, v in d.iteritems(): 68 res[k] = add_func(res.get(k, zero), v) 69 return dict((k, v) for k, v in res.iteritems() if v != zero) 70 return add_dicts