The idea
A list is useful for the sequence of places you visited. A dictionary is useful when you want to look up a fact by a name, such as the next scene after a choice. Lists use numbered positions starting at zero; dictionaries use keys you choose. This is how a few ordinary data structures can describe an adventure without hiding the story inside a tangle of decisions.
A tiny experiment
places = ["shop", "station", "annex"]
clue = {"owner": "Tony", "place": places[0]}
print(places[1])
print(clue["owner"])
print(clue["place"])Reveal the expected output
station Tony shop
Read it one step at a time
- places[1] selects the second list item because the first position is 0.
- The dictionary uses braces. Each colon connects a key to its value; commas separate entries.
- clue["owner"] asks for the value under owner. The string key is different from a list position.
Make one change
Change the stored place from places[0] to places[2]. Which line changes?
Check your thinking
Only the final line changes, from shop to annex.
Keep following the trail
- Activity 08: Choose the allowed commands
- Activity 11: Build your own choice
- Activity 12: Save code as a contribution
Sources & further reading
Companion notes for Coding Adventure by James Colby. Historical claims link to their sources; the examples are written for this learning trail.