Never use mutable defaults
def f(x=[]) creates one list shared across calls. The fix: None sentinel and a fresh list inside the function.
Rare tip: This also applies to {}, set(), and custom mutable objects. Linters like Ruff flag B006 for a reason.
Output
Press Run to execute your code.