0
0
Pythonprogramming~30 mins

Dictionary-based CSV handling in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Dictionary-based CSV handling
📖 Scenario: You work in a small shop and keep track of sales in a CSV file. You want to read this file into a dictionary to easily access and analyze the sales data.
🎯 Goal: Build a Python program that reads sales data from a CSV string into a dictionary, filters sales above a certain amount, and prints the filtered results.
📋 What You'll Learn
Create a dictionary from CSV data with exact keys and values
Add a threshold variable to filter sales
Use a dictionary comprehension to filter sales above the threshold
Print the filtered dictionary
💡 Why This Matters
🌍 Real World
Shops and small businesses often keep sales data in CSV files. Using dictionaries helps quickly find and analyze important sales information.
💼 Career
Data analysts and developers use dictionary-based CSV handling to process and filter data efficiently in many business applications.
Progress0 / 4 steps
1
Create the sales dictionary from CSV data
Create a dictionary called sales with these exact entries: 'apple': 120, 'banana': 80, 'orange': 150, 'grape': 90
Python
Need a hint?

Use curly braces {} to create a dictionary with keys as fruit names and values as sales numbers.

2
Add a sales threshold variable
Create a variable called threshold and set it to 100 to filter sales above this amount
Python
Need a hint?

Just assign the number 100 to the variable threshold.

3
Filter sales above the threshold
Use a dictionary comprehension called filtered_sales to include only items from sales where the sale amount is greater than threshold
Python
Need a hint?

Use {key: value for key, value in dict.items() if condition} to filter the dictionary.

4
Print the filtered sales dictionary
Print the filtered_sales dictionary to display the sales above the threshold
Python
Need a hint?

Use print(filtered_sales) to show the filtered dictionary.