1

Why we change the value of a[0][0] and a[:][0] are all changed with the following list[list[]] initialization method?

a= [[0]*n]*m

a

Out[2]: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

a[0][0]=5

a

Out[4]: [[5, 0, 0], [5, 0, 0], [5, 0, 0]]

Aran-Fey
  • 35,525
  • 9
  • 94
  • 135
jmir
  • 369
  • 2
  • 9

0 Answers0