#536 · Dictionaries and sets · Beginner · 30 XP · about 5 min
Two people filled online shopping carts. Each cart is a dictionary that maps an item to how many of it they want. Write combine_carts(cart1, cart2) that returns one new dictionary with every item from both carts. An item that is in both carts gets the two amounts added together.
The items of cart1 come first, in their order, followed by the items that are only in cart2, in their order. Neither cart may change.
combine_carts({'milk': 1, 'eggs': 12}, {'eggs': 6, 'bread': 2}) # returns {'milk': 1, 'eggs': 18, 'bread': 2} combine_carts({}, {'tea': 3}) # returns {'tea': 3}
Every amount is a whole number of at least 1.
First solves only, ranked by stars and then time.