NOTE: Python indentations were lost in the forum post.
I tested this script in straight Python 2.7 and 3.3 and got this:
coordinates = [[0,0,0]]3
for i in range(3):
coordinates[i][0] = i
coordinates[i][2] = 2i
print(coordinates)
[[2, 0, 4], [2, 0, 4], [2, 0, 4]]
Then, I moved the print function inside the For loop and see that the coordinate values are changing:
coordinates = [[0,0,0]]3
for i in range(3):
coordinates[i][0] = i
coordinates[i][2] = 2i
print(coordinates)
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
[[1, 0, 2], [1, 0, 2], [1, 0, 2]]
[[2, 0, 4], [2, 0, 4], [2, 0, 4]]
The script with the print function outside the loop is only printing the very last coordinate values from the third loop.
So, by using “coordinates = [[0,0,0]]*3” Python will print the coordinates three times on the same line. By using “coordinates = [[0,0,0],[0,0,0],[0,0,0]]”, Python will print the coordinate value of each loop on the same line, like this:
coordinates = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
coordinates[i][0] = i
coordinates[i][2] = 2*i
print(coordinates)
[[0, 0, 0], [1, 0, 2], [2, 0, 4]]