0
0
Pythonprogramming~30 mins

Dictionary use cases in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Dictionary use cases
๐Ÿ“– Scenario: You are managing a small bookstore's inventory. You want to keep track of book titles and their quantities using a dictionary.
๐ŸŽฏ Goal: Build a Python program that creates a dictionary of books and quantities, sets a minimum stock threshold, finds books below that threshold, and prints them.
๐Ÿ“‹ What You'll Learn
Create a dictionary with exact book titles and quantities
Create a variable for minimum stock threshold
Use a dictionary comprehension to find books with stock below the threshold
Print the resulting dictionary of low stock books
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Managing inventory in stores or warehouses often uses dictionaries to track items and quantities.
๐Ÿ’ผ Career
Understanding dictionary operations is essential for data handling, filtering, and reporting in many programming jobs.
Progress0 / 4 steps
1
Create the book inventory dictionary
Create a dictionary called inventory with these exact entries: 'Python Basics': 12, 'Data Science 101': 5, 'Machine Learning': 3, 'Deep Learning': 7, 'AI for Beginners': 2
Python
Need a hint?

Use curly braces {} to create a dictionary with keys as book titles and values as quantities.

2
Set the minimum stock threshold
Create a variable called min_stock and set it to 5 to represent the minimum acceptable stock level.
Python
Need a hint?

Just assign the number 5 to a variable named min_stock.

3
Find books with stock below the threshold
Use a dictionary comprehension to create a new dictionary called low_stock_books that contains only the books from inventory with quantities less than min_stock. Use for book, qty in inventory.items() in your comprehension.
Python
Need a hint?

Use {key: value for key, value in dict.items() if condition} format for dictionary comprehension.

4
Print the low stock books
Write a print statement to display the low_stock_books dictionary.
Python
Need a hint?

Use print(low_stock_books) to show the dictionary.