I am new to Python (and coding) and thought I had a reasonable grasp on the structure but I have been stuck on this one. I want to change the first value of a nested list and then update the value for the next position in the list (e.g., creating grid coordinates as nested lists).
p_d = 3
passes = 1
grid = []
row = []
column = [0, 0, 0]
while passes <= p_d:
row.append(column)
grid.append(row)
passes += 1
for i in range(len(row)):
column[i] = -(p_d - 1) / 2 + i
print(row)
The result is this:
[[-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0]]
But what I really need SHOULD be something like this:
[[-1.0, 0, 0], [0.0, 0, 0], [1.0, 0, 0]]
column, to the outer listrow, three times. So you should expect to see the same list three times...