[ python-Bugs-1084906 ] list initialization bug

SourceForge.net noreply at sourceforge.net
Tue Dec 14 08:01:32 CET 2004


Bugs item #1084906, was opened at 2004-12-14 00:11
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1084906&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: py_py (pingpy)
Assigned to: Nobody/Anonymous (nobody)
Summary: list initialization bug

Initial Comment:
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]


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-12-14 02:01

Message:
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



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1084906&group_id=5470


More information about the Python-bugs-list mailing list