Combine two stock counts

Mediumdictionariesset unionget· 20 XP

Two warehouses each send a dictionary of item to units in stock. The website needs the combined stock for every item either warehouse has.

Write a function combine_stock(a, b) that returns a new dictionary with every item from either dictionary and the sum of its units. Don't change a or b.

How it's checked

Your code runs, then the check below runs and its printed output is compared with ours.

  • combine_stock({"mug": 3, "pen": 10}, {"pen": 5, "cap": 2}) returns {"mug": 3, "pen": 15, "cap": 2}

Hints, the later steps and the answer come with Pro.

def combine_stock(a, b):
    ...