I am trying to replace elements in a 2d list. e-g I have this list
[['0', '0', '0'],
['0', '0', '0'],
['0', '0', '0']]
and I want to convert first row to 1,1,1
here is what I have tried
l = [["0"]*3]*3
for i in range(3):
l[0][i] = "1"
but I am getting the following output instead
[['1', '1', '1'],
['1', '1', '1'],
['1', '1', '1']]
why is it converting all the rows to 1s?
I also tried to insert one element like this
l[1][1] = 1
and this coverts the [1] element of every row to 1 like this
[['0', 1, '0'],
['0', 1, '0'],
['0', 1, '0']]
Am I making a silly mistake or my interpreter has issues?