Exercise 24
Introductory Dictionaries
In this exercise, we’ll use the same data from the previous exercise on lists and use it to learn about Dictionaries or dicts.
Key/Value Structures
You use key=value
data all the time without realizing it. When you read an email, you might have:
1 From: j.smith@example.com
2 To: zed.shaw@example.com
3 Subject: I HAVE AN AMAZING INVESTMENT FOR YOU!!!
On the left are the keys (From, To, Subject), which are mapped to the contents on the right of the :
. Programmers say the key is “mapped” to the value, but they could also say “set to” as in, “I set From
to j.smith@example.com
.” In Python, I might write this same email using a data object like this:
Get Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.