Stocks X74620


Statement
 

pdf   zip

thehtml

Write a function total_stock(stk1, stk2) that provided two product stocks returns the total stock. Each stock is a dictionary whose keys are strings representing product codes (or product names) and values are integers representing the number of available units. For instance, the dictionary {′orange′:5, ′lemon′:2, ′tangerine′:1} represents a stock of five oranges, two lemons and one tangerine.

Sample session
>>> stock_alice = {'orange':5, 'lemon':2, 'tangerine':1}
>>> stock_bob = {'apple':3, 'orange':6, 'tangerine':1}
>>> stock_alice_bob = total_stock(stock_alice, stock_bob)
>>> stock_alice_bob == {'tangerine': 2, 'orange':11, 'lemon':2, 'apple':3} 
True
Information
Author
Language
English
Official solutions
Python
User solutions
Python