def dict_merger_adder(d1, d2, method='merging'):
    """
    Merge two dictionaries adding the values of common keys, as in:
    d1 = {'a': 1, 'b': 1}
    d2 = {'b': 2, 'c': 1}

    If 'merging' as method:
    dn = {'a': 1, 'b': 3, 'c': 1}

    If 'intersection' as method:
    dn = {b': 3}

    Taken from http://stackoverflow.com/questions/10461531/merge-and-sum-of-two-dictionaries

    Dict, Dict -> Dict
    """

    if method == 'intersection':
        dn = {k: d1.get(k, 0) + d2.get(k, 0) for k in set(d1) & set(d2)}
    else:
        dn = {k: d1.get(k, 0) + d2.get(k, 0) for k in set(d1) | set(d2)}
    return dn