I am looking for a Pythonic way (the less code possible) to unite the content of two dictionnaries :
basket1 = {"ham":2,"eggs":3}
basket2 = {"eggs":4,"spam":1}
I want to get a third basket that is going to be the “sum” of the two other, basket 3 should be:
basket3 --> {"ham":2,"eggs":7,"spam":1}
If possible, doing this using set
I’d use a
Counter, which is a kind ofdefaultdictwith some nice properties:which you could convert back into a pure
dictif you wanted: