python dict.add_by_value(dict_2)?
问题 The problem: >>> a = dict(a=1,b=2 ) >>> b = dict( b=3,c=2) >>> c = ??? c = {'a': 1, 'b': 5, 'c': 2} So, the idea is two add to dictionaries by int/float values in the shortest form. Here's one solution that I've devised, but I don't like it, cause it's long: c = dict([(i,a.get(i,0) + b.get(i,0)) for i in set(a.keys()+b.keys())]) I think there must be a shorter/concise solution (maybe something to do with reduce and operator module? itertools?)... Any ideas? Update: I'm really hoping to find