0
0
Pythonprogramming~15 mins

Dictionary creation in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Dictionary Creation
๐Ÿ“– Scenario: You are organizing a small library. You want to keep track of some books and their page counts.
๐ŸŽฏ Goal: Create a dictionary to store book titles as keys and their page counts as values. Then display the dictionary.
๐Ÿ“‹ What You'll Learn
Create a dictionary called books with exact entries
Add a new book entry count variable
Use dictionary comprehension to create a new dictionary with only books having more than 300 pages
Print the new filtered dictionary
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Libraries, bookstores, and reading apps often use dictionaries to store book information and filter books based on user preferences.
๐Ÿ’ผ Career
Understanding dictionary creation and filtering is essential for data handling tasks in programming jobs like data analysis, web development, and software engineering.
Progress0 / 4 steps
1
Create the initial dictionary
Create a dictionary called books with these exact entries: 'Python Basics': 250, 'Data Science': 320, 'Machine Learning': 400, 'Deep Learning': 500
Python
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Add a page count threshold
Create a variable called min_pages and set it to 300 to use as a filter for books with more pages.
Python
Need a hint?

Just assign the number 300 to the variable min_pages.

3
Filter books with dictionary comprehension
Use dictionary comprehension to create a new dictionary called long_books that contains only books from books with page counts greater than min_pages. Use for title, pages in books.items() in your comprehension.
Python
Need a hint?

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

4
Display the filtered dictionary
Print the long_books dictionary to show only books with more than 300 pages.
Python
Need a hint?

Use print(long_books) to display the dictionary.