Command Palette

Search for a command to run...

Hectal
Phase 17: Interviews and Capstone
Python · Exercise 1 of 6Next
Intermediate

Fix the list that remembers too much

The function add_tag(tag, tags=[]) appends tag to a list and returns the list. A call that does not pass tags should start from a new, empty list, but today every such call shares one list. (See Topic 17.1.)

Fix it. If the caller passes a list, append to that same list and return it (the same object). Do not use [] as a default value.

What Check tests

  1. Two calls without a list give independent results
  2. A list passed in is extended and returned (same object)
  3. An empty list passed in is used, not replaced
  4. The default is not a list
  5. The program prints ['a'] then ['b']

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.