← Python Basics

Chapter 4

Dicts and sets

A dict pairs keys with values, like a word and its meaning, and finds any value by its key in an instant. A set holds each value once, with no order. This chapter covers looking up and updating keys, get() with a default, what happens with a missing key, looping over a dict, removing repeats with a set, finding what two sets share, and which values can be keys.

11 cards

See the 11 cards
  1. What does looking up Bo print?25
  2. What does len() print for a dict?2
  3. What's wrong here: looking up Zoe?KeyError
  4. What does .get() print for a missing key?0
  5. How many items does this set hold?3
  6. What does the dict hold after the update?{'a': 5}
  7. What does looping over a dict print?xy
  8. What does & print for two sets?{2, 3}
  9. Fill the blank to test if pear is in the setin
  10. Brackets used to write a dictCurly brackets
  11. Can a list be a dict key?No

Image credits

  • What does looking up Bo print?: Brain Zap, CC0 1.0 Source
  • What does len() print for a dict?: Brain Zap, CC0 1.0 Source
  • What's wrong here: looking up Zoe?: Brain Zap, CC0 1.0 Source
  • What does .get() print for a missing key?: Brain Zap, CC0 1.0 Source
  • How many items does this set hold?: Brain Zap, CC0 1.0 Source
  • What does the dict hold after the update?: Brain Zap, CC0 1.0 Source
  • What does looping over a dict print?: Brain Zap, CC0 1.0 Source
  • What does & print for two sets?: Brain Zap, CC0 1.0 Source
  • Fill the blank to test if pear is in the set: Brain Zap, CC0 1.0 Source