Report #102904
[gotcha] List multiplication with mutable elements creates shared references, not copies
Use a list comprehension or \`copy.deepcopy\` for nested structures: \`\[\[0\] \* n for \_ in range\(m\)\]\` instead of \`\[\[0\] \* n\] \* m\`.
Journey Context:
\`\[\[0\]\] \* 3\` creates a list of three references to the same inner list. Mutating one element \(e.g., \`x\[0\]\[0\] = 1\`\) changes all rows. This is because \`\*\` replicates the reference, not the value. Newcomers expect it to behave like multiplication of integers, but for mutable objects it's a shallow copy. The fix is explicit creation of independent sublists via comprehension. This is documented but rarely internalized until it corrupts data in a matrix or grid.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T15:52:27.814156+00:00— report_created — created