$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #157

Which fix removes the bug?

def add_item(item, bucket=[]):
    bucket.append(item)
    return bucket
  1. Default to None instead
  2. Copy the list on entry
  3. Annotate the parameter
  4. Return a new list only
The default list is created once at definition, so it accumulates across every call.
Play Problem Solving ▸