0
0
Pythonprogramming~15 mins

Why dictionaries are used in Python - See It in Action

Choose your learning style9 modes available
Why dictionaries are used
๐Ÿ“– Scenario: Imagine you run a small library. You want to keep track of books and their authors quickly. You need a way to find the author of any book easily.
๐ŸŽฏ Goal: You will create a dictionary to store book titles and their authors. Then, you will look up authors by book titles to see why dictionaries are useful.
๐Ÿ“‹ What You'll Learn
Create a dictionary called library with exact book-author pairs
Create a variable called book_to_find with a specific book title
Use dictionary access to get the author of book_to_find
Print the author name
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Libraries, stores, and many apps use dictionaries to quickly find information by a unique key like a book title or product code.
๐Ÿ’ผ Career
Knowing how to use dictionaries helps you work with data efficiently, a key skill in programming jobs like web development, data analysis, and software engineering.
Progress0 / 4 steps
1
Create the library dictionary
Create a dictionary called library with these exact entries: 'The Hobbit': 'J.R.R. Tolkien', '1984': 'George Orwell', 'Pride and Prejudice': 'Jane Austen'
Python
Need a hint?

Use curly braces {} to create a dictionary. Each entry has a book title as key and author as value.

2
Choose a book to find
Create a variable called book_to_find and set it to the string '1984'
Python
Need a hint?

Use = to assign the string '1984' to the variable book_to_find.

3
Find the author using the dictionary
Create a variable called author and set it to the value from library for the key book_to_find
Python
Need a hint?

Use square brackets [] with the dictionary name and key variable to get the value.

4
Print the author
Write a print statement to display the value of the variable author
Python
Need a hint?

Use print(author) to show the author's name on the screen.