$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #144

What is the correct fix?

def add(item, bucket=[]):
    bucket.append(item)
    return bucket
  1. Default to None, build inside
  2. Default to a tuple instead
  3. Copy bucket before append
  4. Return a new list each call
A mutable default is created once and shared across every call.
Play Problem Solving ▸