I need to add two hash tables in python. However, "+" does not do that:
d1={1:1}
d2={1:2,2:5}
d3=d1+d2
I need d3={1:3,2:5}. I appreciate any suggestion.
Use collections.Counter
:
>>> from collections import Counter
>>> Counter(d1) + Counter(d2)
Counter({2: 5, 1: 3})