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]]
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]]