[New-bugs-announce] [issue35515] Matrix operator star creates a false matrix

Arnaud report at bugs.python.org
Mon Dec 17 04:04:28 EST 2018


New submission from Arnaud <xda at abalgo.com>:

It seems that the definition of a matrix like this:
a=[[0,0]]*4
does not create the matrix correctly by create 4 times the same pointer.
After the matrix creation, a
print(a)
gives the following result:
[[0, 0], [0, 0], [0, 0], [0, 0]]
which looks normal
print(type(a)) and print(type(a[1]) give also the correct result:
list

But when we try to change a matrix element:
a[2][0]=1
print(a)
gives a false result:
[[1, 0], [1, 0], [1, 0], [1, 0]]

When the matrix definition is done like this:
a=[[0, 0], [0, 0], [0, 0], [0, 0]]
the behavior is "as expected"
a[2][0]=1
print(a)
gives the correct result:
[[0, 0], [0, 0], [1, 0], [0, 0]]

----------
components: Interpreter Core
files: python_bugreport.py
messages: 331955
nosy: xda at abalgo.com
priority: normal
severity: normal
status: open
title: Matrix operator star creates a false matrix
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6
Added file: https://bugs.python.org/file48001/python_bugreport.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35515>
_______________________________________


More information about the New-bugs-announce mailing list