'strang behavior of 2d array
I creat a 2d array using two methods they look the same
helper1=[[]]*5
helper=[[] for i in range(5)]
when I append new element to the arrays, they behave differently
helper1[0].append(1)
result is [[1], [1], [1], [1], [1]]
helper[0].append(1)
result is [[1], [], [], [], []]
I am surprised by the first outcome , why it is so? thanks !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
