[issue16756] buggy assignment to items of a list created by a * operator

jp report at bugs.python.org
Sun Dec 23 17:33:03 CET 2012


New submission from jp:

The following code: 

li = [[1,0]]*5
a = [[1,10], [2,20], [3,30]]
for line in a:
    li[line[0]][0] = 2
print(li)

prints [[2,0],[2,0],[2,0],[2,0],[2,0]], but should print [[1,0],[2,0],[2,0],[2,0],[1,0]]. 

The output is correct if you, instead of using li = [[1,0]]*5, initialize the array as follows:

li = []
for i in range(5): li.append([1,0])

----------
components: Interpreter Core
messages: 177995
nosy: jenda.petrov at gmail.com
priority: normal
severity: normal
status: open
title: buggy assignment to items of a list created by a * operator
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16756>
_______________________________________


More information about the Python-bugs-list mailing list