In this article https://florimond.dev/blog/articles/2018/08/python-mutable-defaults-are-the-source-of-all-evil/ the following code is posted as the pythonic solution:
def append(element, seq=None):
if seq is None:
seq = []
seq.append(element)
return seq
To the problem of having default arguments with lists. To me it does not seem pretty and I wondered if there is someway to be able to have a mutable defaults and no if statement. Something like:
def append(element, seq=defaultlist([])):
seq.append(element)
return seq