Solved

The evening record contains the morning reading?!

EmmaCodesOP

Stage 1 prediction was so wrong. How can two separate calls share a list?

5

Comments 5

Join the discussion

Already have an account? Log in

  1. LiamByte Solutionreplies: 2

    Default values are evaluated once, when the function is defined — not on each call. So flags=[] creates one list that every call without flags reuses. Append to it once and every later call sees that item.

    10
      1. FreyaL

        Every Python developer hits this once. Linters (ruff, pylint) flag mutable defaults automatically.

        4
    1. HenryWrites

      The standard fix is in stage 3: default to None and create a new list inside the function if it's None.

      3
      1. ElaKowalska

        This is the one I always mention when people say Python has no gotchas 😄

        3