classification
Title: 2D list with Bugs when defined by using Multiplication
Type: behavior Stage: resolved
Components: Build Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: Yaowei Zhang, ezio.melotti
Priority: normal Keywords:

Created on 2017-02-17 01:55 by Yaowei Zhang, last changed 2017-02-17 02:17 by ezio.melotti. This issue is now closed.

Messages (2)
msg287975 - (view) Author: Yaowei Zhang (Yaowei Zhang) Date: 2017-02-17 02:03
#If we define a list by:
nums = [[0]*3]*3
#nums = [[0,0,0],[0,0,0],[0,0,0]]
nums[0][1] = 1
print(mums)
# the result is
[[0,1,0],[0,1,0],[0,1,0]]
#I think it is because all the line use the same list variable, but it suppose #not.
msg287977 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2017-02-17 02:17
Not a bug, see https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list and https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x
History
Date User Action Args
2017-02-17 02:17:02ezio.melottisetstatus: open -> closed

assignee: ezio.melotti

nosy: + ezio.melotti
messages: + msg287977
resolution: not a bug
stage: resolved
2017-02-17 02:03:45Yaowei Zhangsettype: behavior
messages: + msg287975
components: + Build, - Library (Lib)
2017-02-17 01:55:48Yaowei Zhangcreate