The Mutable Default Argument

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • medium
  • Pro

A function takes an optional list that defaults to an empty list, and appends to it. Each call seems to remember items from earlier calls. Explain why, and the idiomatic fix.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →