I want to merge two dictionaries A and B such that the result contains:
>>> def f(x,y): ... return x*y ... >>> dict([(k,v) for k,v in A.items()] + [ (k,v) if k not in A else (k,f(A[k],B[k])) for k,v in B.items()]) {1: 1, 2: 6, 7: 3}