The dragon explains
Changing a list
The dragon: Lists can change AFTER you make them. append adds; remove takes away. Both change the list IN PLACE.
The dragon: list.append(item) adds one item to the end.
example.pyPython 3hoard = ["gold", "gems"]hoard.append("sword")print(hoard)
Output['gold', 'gems', 'sword']The dragon: list.remove(item) takes ONE matching item out, by its VALUE — not by counting a position.
example.pyPython 3hoard = ["gold", "gems", "sword"]hoard.remove("gems")print(hoard)
Output['gold', 'sword']The dragon: Now the surprising part. treasury = hoard does NOT make a copy — it makes treasury just another name for the SAME list.
example.pyPython 3hoard = ["gold", "gems"]treasury = hoardtreasury.append("sword")print(hoard)
Output['gold', 'gems', 'sword']The dragon: hoard shows the sword too, even though you only touched treasury — because hoard and treasury were never two separate lists. They're one list with two names.
example.pyPython 3hoard = ["gold", "gems"]treasury = hoardtreasury.append("sword")print(hoard)
The dragon: This is only true for LISTS, because they're mutable. Numbers and text don't do this — but this is a genuinely important thing to know about lists specifically.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 1
hoard = ["gold"]. treasury = hoard. treasury.append("gems"). What does print(hoard) show?
question.pyPython 3hoard = ["gold"]treasury = hoardtreasury.append("gems")print(hoard)
- ['gold', 'gems'] — hoard shows the change tooCorrect
- ['gold'] — hoard is unaffected, only treasury changed
- This causes an error, because treasury was never really defined
Why: hoard shows 'gems' too — hoard and treasury were always the same list underneath, just with two different names pointing at it. Changing the list through EITHER name changes the one thing both names refer to.
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
A row of treasures. look() tells you the name of what's on the dragon's tile. The first step is done: walk, then bag.append(look()). Do the same for the other two tiles, then print(bag) — and watch the bag fill up in the dragon's memory as it walks.
- +2
PracticeTwo more, on your own
This lesson is part of PRO.
PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.
Unlock this lesson with PROStuck three times? The game offers the answer — unasked.