Neha Joshi2 months agoMost voted9
Default values are evaluated once, when the def line runs, not every time you call the function. So both calls get the same list object.
Usual fix:
def add(x, lst=None):
if lst is None:
lst = []
lst.append(x)
return lstVery common interview question btw