0
Lists & Dicts1 / 4

CRASH COURSE

Lists & Dicts

A list holds an ordered collection of items. You can add, remove, and loop over them.

  • A dict (dictionary) maps keys to values, like a real dictionary maps words to definitions.
  • Lists and dicts are the backbone of almost every real program — games, apps, and websites all use them.
inventory = ["sword", "shield", "potion"]
inventory.append("bow")

for item in inventory:
    print(f"You have: {item}")

player = {"name": "Ada", "hp": 100, "level": 5}
print(player["name"])
player["hp"] -= 20
print(f"HP after the trap: {player['hp']}")