Maybe I am just not understanding list indexing correctly, but when I run the following code:
myList= [['nan'] *4]*4
for i in range(4):
for j in range(4):
if [i,j] == [2,1]:
myList[i][j]=1
print('['+str(i)+','+str(j)+'] --> '+str(myList[i][j]))
I believe it should output
[0][0] --> nan
[0][1] --> nan
[0][2] --> nan
[0][3] --> nan
[1][0] --> nan
[1][1] --> nan
[1][2] --> nan
[1][3] --> nan
[2][0] --> nan
[2][1] --> 1
[2][2] --> nan
[2][3] --> nan
[3][0] --> nan
[3][1] --> nan
[3][2] --> nan
[3][3] --> nan
However, it actually outputs
[0][0] --> nan
[0][1] --> nan
[0][2] --> nan
[0][3] --> nan
[1][0] --> nan
[1][1] --> nan
[1][2] --> nan
[1][3] --> nan
[2][0] --> nan
[2][1] --> 1
[2][2] --> nan
[2][3] --> nan
[3][0] --> nan
[3][1] --> 1
[3][2] --> nan
[3][3] --> nan
What's more, if I do
myList= [['nan'] *4]*4
for i in range(4):
for j in range(4):
if i==1 and j==2:
myList[i][j]=1
print('['+str(i)+']['+str(j)+'] --> '+str(myList[i][j]))
I get
[0][0] --> nan
[0][1] --> nan
[0][2] --> nan
[0][3] --> nan
[1][0] --> nan
[1][1] --> nan
[1][2] --> 1
[1][3] --> nan
[2][0] --> nan
[2][1] --> nan
[2][2] --> 1
[2][3] --> nan
[3][0] --> nan
[3][1] --> nan
[3][2] --> 1
[3][3] --> nan
Why is it in the first case changing the value at [3][1], and in the later case at [1][2] and [3][2]? The if statement should never be reached for any index except [2][1] in either case! Also, why is are the two if statements not equivalent?