0
0
Pythonprogramming~15 mins

Dictionary keys, values, and items in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Explore Dictionary Keys, Values, and Items
๐Ÿ“– Scenario: You work in a small bookstore. You have a dictionary that stores book titles as keys and their prices as values.You want to learn how to get just the book titles, just the prices, and both together in pairs.
๐ŸŽฏ Goal: Build a program that shows how to get the keys, values, and items from a dictionary.
๐Ÿ“‹ What You'll Learn
Create a dictionary called books with exact entries: 'Python Basics': 29.99, 'Data Science': 39.95, 'Machine Learning': 49.50
Create a variable called book_titles that stores the keys of books
Create a variable called book_prices that stores the values of books
Create a variable called book_items that stores the items of books
Print book_titles, book_prices, and book_items in that order
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Dictionaries are used to store related data, like product names and prices, user information, or settings. Knowing how to get keys, values, and items helps you access and use this data easily.
๐Ÿ’ผ Career
Many programming jobs require working with dictionaries or similar data structures. Being comfortable with keys, values, and items is essential for data processing, web development, and automation tasks.
Progress0 / 4 steps
1
Create the books dictionary
Create a dictionary called books with these exact entries: 'Python Basics': 29.99, 'Data Science': 39.95, 'Machine Learning': 49.50
Python
Need a hint?

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

2
Get the keys and values
Create a variable called book_titles that stores the keys of books using the keys() method. Then create a variable called book_prices that stores the values of books using the values() method.
Python
Need a hint?

Use dictionary.keys() to get all keys and dictionary.values() to get all values.

3
Get the items
Create a variable called book_items that stores the items of books using the items() method.
Python
Need a hint?

Use dictionary.items() to get all key-value pairs as tuples.

4
Print the keys, values, and items
Print the variables book_titles, book_prices, and book_items in that order, each on its own line.
Python
Need a hint?

Use three print() statements, one for each variable.