Report #22508
[gotcha] Multiplying a list containing mutable objects creates shared references causing spooky action at a distance
Use list comprehensions \[expression for \_ in range\(n\)\] to create independent objects; never use \[mutable\_obj\] \* n for mutable contents
Journey Context:
The multiplication operator on lists shallow-copies the references. \[\[0\]\] \* 3 creates three references to the exact same inner list. Modifying one element appears to modify all, causing subtle bugs in matrix operations or parallel data structures. This differs from immutable contents \(int, str\) where sharing is safe. Always use \[\[0\] for \_ in range\(3\)\] for independent mutable objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:11:11.306528+00:00— report_created — created