1def append_to(element, to=[]):
2 to.append(element)
3 return to
4
5print(append_to(1)) # [1]
6print(append_to(2)) # Expected [2], got [1, 2]
7print(append_to(3)) # Expected [3], got [1, 2, 3]
no lines flagged
#016PracticeEasy8 min · 50 XP
Mutable Default Argument
This function accumulates results across calls because of a classic Python pitfall. Find the fault.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.