The dragon explains
Real copies, and the None trap
The dragon: You know treasury = hoard shares ONE list. Here's how to actually get a second, independent one.
The dragon: hoard.copy() builds a brand new list with the same items — mutating the copy never touches the original.
example.pyPython 3hoard = ["gold", "gems"]treasury = hoard.copy()treasury.append("sword")print(hoard)
Output['gold', 'gems']The dragon: hoard[:] — a slice with nothing on either side of the colon — does the exact same thing. Both are real copies.
example.pyPython 3hoard = ["gold", "gems"]treasury = hoard[:]print(treasury == hoard, treasury is hoard)
OutputTrue FalseThe dragon: Now a completely different trap. Some list methods change the list AND hand you back nothing.
The dragon: hoard.sort() sorts hoard in place — and returns None. Assigning that None back to hoard destroys it.
example.pyPython 3hoard = ["gems", "gold"]hoard = hoard.sort()print(hoard)
OutputNoneThe dragon: The fix: call .sort() on its own line, with nothing capturing its result. hoard is already sorted — no reassignment needed.
example.pyPython 3hoard = ["gems", "gold"]hoard.sort()print(hoard)
Output['gems', 'gold']The dragon: .append(), .reverse(), and .sort() all work this way: they mutate and return None. Never write x = x.append(...) either.
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 2
hoard = ["b", "a"]. hoard = hoard.sort(). What does print(hoard) show?
question.pyPython 3hoard = ["b", "a"]hoard = hoard.sort()print(hoard)
- NoneCorrect
- ['a', 'b'] — sorted correctly
- ['b', 'a'] — unsorted, because sort failed
Why: .sort() genuinely sorts the list in place, but its RETURN VALUE is None — that's true of append() and reverse() too. hoard = hoard.sort() takes the correctly-sorted list and immediately overwrites it with None. The fix is just hoard.sort() on its own, no assignment.
Question 2 of 2
hoard = ["gold"]. treasury = hoard.copy(). treasury.append("gems"). Does hoard change?
question.pyPython 3hoard = ["gold"]treasury = hoard.copy()treasury.append("gems")print(hoard)
- No — hoard still just says ['gold']Correct
- Yes — hoard becomes ['gold', 'gems'] too, same as with plain =
Why: .copy() (and hoard[:]) are the actual fix for s3's aliasing surprise: they build a second, independent list, so treasury and hoard no longer point at the same thing.
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
hoard = ["gold", "gems"]. This time, make treasury an ACTUAL COPY with hoard.copy() — not treasury = hoard. Then treasury.append("sword") and print(hoard). It should NOT have the sword.
- +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.