Report #94081
[gotcha] List multiplication with mutable elements creates shared references not distinct copies
Use a list comprehension \`\[ \[0\]\*3 for \_ in range\(3\) \]\` to ensure a new inner list is created for each iteration, or use \`copy.deepcopy\` for nested structures
Journey Context:
The \`\*\` operator on sequences performs shallow copying. When multiplying a list containing a mutable object \(like another list\), the outer list contains multiple references to the exact same inner object. Modifying one element appears to modify all others. A list comprehension is preferred because the expression is re-evaluated for each iteration, creating distinct objects. \`copy.deepcopy\` is an alternative but has significant overhead; for simple cases, the comprehension is both idiommatic and performant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:30:13.380428+00:00— report_created — created