Lad wrote: > Let's suppose I have > > a={'c':1,'d':2} > b={'c':2} > but > a.update(b) > will make > {'c': 2, 'd': 2} > > and I would need > {'c': 3, 'd': 2} > > (because `c` is 1 in `a` dictionary and `c` is 2 in `b` dictionary, so > 1+2=3) > > How can be done that?
dict([(k, a.get(k, 0) + b.get(k,0)) for k in set(a.keys() + b.keys())]) -- http://mail.python.org/mailman/listinfo/python-list