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
  • 39,665
  • 11
  • 104
  • 149
jmir
  • 399
  • 2
  • 9

0 Answers0