In this lesson, you’ve learned how to go through dictionaries and access keys and values in different ways. Specifically, you have seen how to:
- Use a key to get a value from a dictionary
- Check for existence of keys
- Remove a key: value pair from a dictionary
- Iterate through keys and values in dictionaries
Instructions
We have provided a pack of tarot cards, tarot
. You are going to do a three card spread of your past, present, and future.
Create an empty dictionary called spread
.
The first card you draw is card 13. Pop the value assigned to the key 13
out of the tarot
dictionary and assign it as the value of the "past"
key of spread
.
The second card you draw is card 22. Pop the value assigned to the key 22
out of the tarot
dictionary and assign it as the value of the "present"
key of spread
.
The third card you draw is card 10. Pop the value assigned to the key 10
out of the tarot
dictionary and assign it as the value of the "future"
key of spread
.
Iterate through the items in the spread
dictionary and for each key: value pair, print out a string that says:
Your {key} is the {value} card.
Congratulations! You have learned about how to modify and use dictionaries.
Hit the Run
button one more time when you are ready to continue.