python dict.add_by_value(dict_2)?

Solution 1:

Easiest to just use a Counter

>>> from collections import Counter
>>> a = dict(a=1,b=2    )
>>> b = dict(    b=3,c=2)
>>> Counter(a)+Counter(b)
Counter({'b': 5, 'c': 2, 'a': 1})
>>> dict(Counter({'b': 5, 'c': 2, 'a': 1}))
{'a': 1, 'c': 2, 'b': 5}

Solution 2:

solving not in terms of "length" but performance, I'd do the following:

>>> from collections import defaultdict
>>> def d_sum(a, b):
        d = defaultdict(int, a)
        for k, v in b.items():
            d[k] += v
        return dict(d)
>>> a = {'a': 1, 'b': 2}
>>> b = {'c': 2, 'b': 3}
>>> d_sum(a, b)
{'a': 1, 'c': 2, 'b': 5}

it's also py3k-compatible, unlike your original code.