Python二维数组,坑苦了
myList = [[ 0 ] * 3 ] * 4 |
但是当操作myList[0][1] = 1时,发现整个第二列都被赋值,变成
[[0,1,0],
[0,1,0],
[0,1,0],
[0,1,0]]
myList
=
[([
0
]
*
3
)
for
i
in
range
(
4
)]
避免浅拷贝。。。
myList = [[ 0 ] * 3 ] * 4 |
但是当操作myList[0][1] = 1时,发现整个第二列都被赋值,变成
[[0,1,0],
[0,1,0],
[0,1,0],
[0,1,0]]
myList
=
[([
0
]
*
3
)
for
i
in
range
(
4
)]
避免浅拷贝。。。