2
b = [[1,1],[1,0]]
a = [[0]*2]*2
for i in range(2):
    for j in range(2):
        a[i][j] = b[i][j]
print(a)
print(b)

and the outputs are:

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

I don't know where going wrong. Isn't the a should be the exact same as the b?

miradulo
  • 28,857
  • 6
  • 80
  • 93
Victor. L
  • 145
  • 2
  • 9
  • 1
    why do you want to copy an array using loops ? There are shorter and faster ways. – YOLO Mar 18 '18 at 21:29
  • @miradulo thank you! @Manish Saraswat I know, but I just wanna know what is wrong with `a = [[0]*2]*2` – Victor. L Mar 18 '18 at 21:41
  • @Victor.L No problem! Feel free to mark your question as a duplicate of that one - it doesn't negatively affect you, and will help others find their way to that answer. Thanks! – miradulo Mar 18 '18 at 21:44

0 Answers0