Learn
Using Dictionaries
Review

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
  • Find the length of a dictionary
  • Remove a key: value pair from a dictionary
  • Iterate through keys and values in dictionaries

Instructions

1.

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.

2.

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.

3.

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.

4.

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.

5.

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.
6.

Congratulations! You have learned about how to modify and use dictionaries.

Folder Icon

Sign up to start coding

Already have an account?