1

I encounter a problem when I try to use a list as a 2d array.

li = [[0]*3]*3
print li
li[0][0] = 1
print li

then the weird thing happens the output would be:

[[0,0,0],[0,0,0],[0,0,0]]
[[1,0,0],[1,0,0],[1,0,0]]

why it's not

[[1,0,0],[0,0,0],[0,0,0]]
Keiser He
  • 11
  • 2

0 Answers0