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: list initialization bug
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: pingpy, rhettinger
Priority: normal Keywords:

Created on 2004-12-14 05:11 by pingpy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg23688 - (view) Author: py_py (pingpy) Date: 2004-12-14 05:11
Python 2.3.4 running on Linux Redhat 9.1

The following initialization produces an unwanted (I
think) side effect,

a,b=2*[[0]*2]

It seems that both a and b point to the same address
For example,
a[1]=1
gives me
a=[0,1]
but produces, as a side effect,
b=[0,1] !!!!

However, the following works
a,b = [[0]*2,[0]*2]
msg23689 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-12-14 07:01
Logged In: YES 
user_id=80475

Thanks for the report; however, this is correct behavior. 

Learning about shallow vcrsus deep copies is a key to
understanding the language.  Start by reading the FAQ:

http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list

History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41318
2004-12-14 05:11:43pingpycreate