[issue43581] array assignment error

2021-03-21 Thread John Cena


John Cena  added the comment:

You are actually creating 4 references to the same list(See the ending *4). 
This is how python behaves. See the below link as well

https://stackoverflow.com/questions/240178/list-of-lists-changes-reflected-across-sublists-unexpectedly

--
nosy: +crazyguyx4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43581] array assignment error

2021-03-21 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43581] array assignment error

2021-03-21 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

By using * 4 in the end you are making four lists having same reference. Hence 
change in one causes change in other 4 lists.

Relevant FAQ : 
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43581] array assignment error

2021-03-21 Thread Vedran Čačić

Vedran Čačić  added the comment:

All three words in the title are wrong. :-D

--
nosy: +veky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43581] array assignment error

2021-03-21 Thread Wen Hao


New submission from Wen Hao :

>>>mat = [[0]*4]*4
>>> mat
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
>>> mat[1][2]=1
>>> mat
[[0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]]

--
components: Build
messages: 389230
nosy: haowenqi.zz
priority: normal
severity: normal
status: open
title: array assignment error
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com