This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 3.4 bugs
Type: behavior Stage:
Components: macOS Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, ronaldoussoren, skip.montanaro, vasya yugov
Priority: normal Keywords:

Created on 2015-06-18 11:01 by vasya yugov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg245460 - (view) Author: vasya yugov (vasya yugov) Date: 2015-06-18 11:01
This code:

w = [[0] * 2] * 2
w[1][1] = 1
print(w)

prints
[[0, 1], [0, 1]]
Is it a bug?
msg245462 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2015-06-18 11:29
Not a bug. The two elements of w are references to the same list:

>>> w = [[0] * 2] * 2
>>> w
[[0, 0], [0, 0]]
>>> [id(elt) for elt in w]
[21743952, 21743952]
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68651
2015-06-18 11:29:20skip.montanarosetstatus: open -> closed

nosy: + skip.montanaro
messages: + msg245462

resolution: not a bug
2015-06-18 11:01:13vasya yugovcreate