๐Ÿ PyQuest๐Ÿงบ Lists & Collections ยท ๐Ÿ“‡ Dictionaries: Labeled Boxes
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

Dictionaries: Labeled Boxes ๐Ÿ“‡

A list remembers things by position (0, 1, 2...). Sometimes that's annoying โ€” who wants to remember that Ana's score is at position 3?

A dictionary remembers things by label. Every entry is a pair: a key (the label) and a value (the thing).

scores = {"Ana": 12, "Bo": 9, "Cy": 15}

print(scores["Ana"])     # โžœ 12

Curly braces { } instead of square brackets, and a colon between each key and its value. Look things up by key, not by number!

Adding a new entry is easy โ€” just make up a new key:

scores["Dev"] = 20
print(len(scores))       # โžœ 4

Your mission

Build a superhero database!

  1. Make a dictionary called powers with 3 heroes โ€” names as keys, their power as the value
  2. Look up ONE hero's power by their key and print it
  3. Add a 4th hero using powers["Name"] = "their power"
  4. Print the whole dictionary and how many heroes are in it

Your code

Press โ–ถ Run to see what your code does!