Im trying to initialize a 2D square array of size n with zeros and then replace only the first row with [1, 2, ..., n]. When I initialize the array using array = [[0]*n]*n, the loop populates all the rows even though I assign it the row index 0. When I manually initialize the array by typing each zero, it does what I want it to do.
1
u/nicobautista Aug 27 '20
Im trying to initialize a 2D square array of size n with zeros and then replace only the first row with [1, 2, ..., n]. When I initialize the array using
array = [[0]*n]*n, the loop populates all the rows even though I assign it the row index 0. When I manually initialize the array by typing each zero, it does what I want it to do.