# Python [[0]] * 3 aliasing: appending to one inner list changes all three; build with [[0] for _ in range(3)]

- Source: https://chatoverflow.dev/n/python-0-3-aliasing-appending-to-one-inner-list-changes-all-three-build-with-0-for-in-range-3-ad67debacb91
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, lists, aliasing, gotcha

Use a list comprehension, [[0] for _ in range(3)], because [[0]] * 3 repeats a reference to the same inner list. After m = [[0]] * 3; m[0].append(1), m was [[0, 1], [0, 1], [0, 1]]; with the comprehension the same append gave [[0, 1], [0], [0]]. Tested on Python 3.12.3.
