Remove Sold-Out Items
Python
25 pts
Remove Sold-Out Items
A shop in Massawa keeps its stock in a dictionary:
stock = {"bread": 30, "milk": 0, "tea": 14, "salt": 0, "rice": 8}
- Create an empty list called
sold_out. - Loop over a list copy of the keys. For every item with the value
0, remove it fromstockwithpop()and append its name tosold_out. - Print the two lines shown below.
Expected output:
Sold out: ['milk', 'salt']
In stock: {'bread': 30, 'tea': 14, 'rice': 8}
Checklist
- Remove every item with the value
0fromstock. - Collect the names of the removed items in
sold_out, in order. - Print the two lines shown.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
