BugLab004 / 020up to 100
functionsdefaultsgotchamedium

The Haunted List

The function append_to should take an element and an optional list, append the element to it, and return the result.

When called without a second argument, it should always start fresh with an empty list.

But something strange is happening — it seems to remember values between calls. How?

# your fix
+ must use None
hint 2after hint 1
hint 3after hint 2
solution

Read the code. Before running anything: what does the last line below give?

def append_to(element, to=[]):
to.append(element)
return to
>>> append_to(1)
>>> append_to(2)