I have a list of lists and I want to assign to the first element of each list a value in order from 0 to 3. I wrote the following code:
var = [[-1] * 5] * 4
for i in range(4):
var[i][0] = i+1
print(var)
The output is
[[4,-1,-1,-1,-1],
[4,-1,-1,-1,-1],
[4,-1,-1,-1,-1],
[4,-1,-1,-1,-1]]
But it should be:
[[1,-1,-1,-1,-1],
[2,-1,-1,-1,-1],
[3,-1,-1,-1,-1],
[4,-1,-1,-1,-1]]
How do I do it?