[Python-bugs-list] [ python-Bugs-455694 ] bug in list append, or list multiply?

noreply@sourceforge.net noreply@sourceforge.net
Mon, 27 Aug 2001 01:15:37 -0700


Bugs item #455694, was opened at 2001-08-27 01:15
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=455694&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: bug in list append, or list multiply?

Initial Comment:
Python 2.1.1 (Windows NT 4)

>>> x=6*[[]]
>>> x
[[], [], [], [], [], []]
>>> x[3].append(7)
>>> x
[[7], [7], [7], [7], [7], [7]]

But, I was expecting:

[[], [], [], [7], [], []]

So I then tried this:

>>> x=[[],[],[],[],[],[]] # instead of x=6*[[]]
>>> x[3].append(7)
>>> x
[[], [], [], [7], [], []]

And it worked.

----

I imagine what is happening is that 6*[[]] creates 6 pointers to the same empty list?  But, if so, 
the python docs (http://www.python.org/doc/current/lib/typesseq.html) imply otherwise:

s * n , n * s yields n _copies_ of s concatenated

Anyway, I'm confused.

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

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