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