# [[0,0,0]]*3 Not working in python console

Hello all,

There is an annoying bug I wanted to highlight:

#coordinates = [[0,0,0]]*3 # Not working
coordinates = [[0,0,0],[0,0,0],[0,0,0]] # Working

for i in range(3):
coordinates[i][0] = i
coordinates[i][2] = 2*i

print(coordinates)

I am using Trelis 16.5

Thank you,

Have a good evening

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] = 2
i

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] = 2
i
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]]

Hello,

You are right, I am sorry.

This is due to a strange behaviour of python reported also there: stackoverflow.com/questions/127 … t-of-lists

coordinates1 = [[0,0,0]]*3

and

coordinates2 = [[0,0,0],[0,0,0],[0,0,0]]

Although identical when printed does not behave the same way.

Thank you for your help