0
0
Pythonprogramming~15 mins

Why structured data formats are used in Python - See It in Action

Choose your learning style9 modes available
Why structured data formats are used
📖 Scenario: Imagine you work in a small library. You want to keep track of books and their details like title, author, and year. You need a way to organize this information so you can find and use it easily.
🎯 Goal: You will create a simple program that uses a structured data format (a dictionary) to store book information. Then, you will add a filter to find books published after a certain year. Finally, you will print the filtered books.
📋 What You'll Learn
Create a dictionary with book titles as keys and their details as nested dictionaries
Create a variable to hold the year threshold
Use a dictionary comprehension to filter books published after the threshold year
Print the filtered dictionary
💡 Why This Matters
🌍 Real World
Libraries, stores, and many businesses use structured data formats like dictionaries to organize and quickly find information.
💼 Career
Knowing how to organize and filter data is important for jobs in data analysis, software development, and many other tech roles.
Progress0 / 4 steps
1
Create the books dictionary
Create a dictionary called books with these exact entries: 'The Hobbit' with details {'author': 'J.R.R. Tolkien', 'year': 1937}, '1984' with details {'author': 'George Orwell', 'year': 1949}, and 'Python 101' with details {'author': 'Michael Driscoll', 'year': 2014}.
Python
Need a hint?

Use a dictionary with book titles as keys and another dictionary for details as values.

2
Set the year threshold
Create a variable called year_threshold and set it to 1950.
Python
Need a hint?

Just create a variable and assign the number 1950 to it.

3
Filter books published after the threshold
Use a dictionary comprehension to create a new dictionary called recent_books that includes only books from books where the year is greater than year_threshold.
Python
Need a hint?

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

4
Print the filtered books
Write a print statement to display the recent_books dictionary.
Python
Need a hint?

Use print(recent_books) to show the filtered dictionary.