mutation — why your code mysteriously breaks6 / 8
mutation and the action-at-a-distance bug
This is the single most famous Python bug — and AI ships it constantly.
The function add_pet uses pets=[] as a default. The trap: that empty
list is created once, when the function is defined, not each time
it's called. Every call without an argument shares the same list.
Run it as-is and you'll see the second call returns ["luna", "moose"]
instead of just ["moose"]. Fix line 1 so each call without an argument
gets a fresh list.
Expected output:
['luna']
['moose']
The break is on line 1 — but read the whole snippet first.
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _