Removing dictionary entries
๐ Scenario: You are managing a small store's inventory. Some products are out of stock and need to be removed from the inventory list.
๐ฏ Goal: Build a program that removes products with zero stock from the inventory dictionary.
๐ What You'll Learn
Create a dictionary called
inventory with product names as keys and stock counts as values.Create a list called
out_of_stock to hold products with zero stock.Use a
for loop to find products with zero stock and add them to out_of_stock.Remove all products in
out_of_stock from inventory.Print the updated
inventory dictionary.๐ก Why This Matters
๐ Real World
Managing inventory is common in stores and warehouses to keep track of available products and remove items that are not currently sellable.
๐ผ Career
Knowing how to manipulate dictionaries and remove entries based on conditions is useful for data cleaning and management tasks in many programming jobs.
Progress0 / 4 steps