0
0
Pythonprogramming~30 mins

Nested dictionaries in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Dictionaries
๐Ÿ“– Scenario: You work at a small bookstore. You want to organize information about books by category and details like author and price.
๐ŸŽฏ Goal: Create a nested dictionary to store book details by category, then print the price of a specific book.
๐Ÿ“‹ What You'll Learn
Create a nested dictionary with categories as keys and dictionaries of books as values
Each book dictionary should have keys 'author' and 'price'
Access nested dictionary values using keys
Print the price of a specific book
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Nested dictionaries help organize complex data like product catalogs, user profiles, or settings grouped by categories.
๐Ÿ’ผ Career
Understanding nested dictionaries is important for data handling, configuration management, and working with JSON-like data in many programming jobs.
Progress0 / 4 steps
1
Create the nested dictionary
Create a dictionary called bookstore with two categories: 'Fiction' and 'Science'. Each category should be a dictionary with these books and details exactly:
'Fiction': {'The Great Gatsby': {'author': 'F. Scott Fitzgerald', 'price': 10.99}, '1984': {'author': 'George Orwell', 'price': 8.99}}
'Science': {'A Brief History of Time': {'author': 'Stephen Hawking', 'price': 15.99}, 'The Selfish Gene': {'author': 'Richard Dawkins', 'price': 12.99}}
Python
Need a hint?

Use curly braces to create dictionaries. The value for each category is another dictionary with book titles as keys.

2
Set the category to look up
Create a variable called category and set it to the string 'Fiction'.
Python
Need a hint?

Just assign the string 'Fiction' to the variable category.

3
Access the nested dictionary
Create a variable called book and set it to the string '1984'. Then create a variable called price and set it to the price of the book '1984' in the category inside bookstore.
Python
Need a hint?

Use square brackets to access nested dictionaries: bookstore[category][book]['price'].

4
Print the price
Write a print statement to display the price stored in the variable price.
Python
Need a hint?

Use print(price) to show the price.