I'm creating a list of lists of lists. When I choose a specific index, it sets several list entries simultaneously. What's going on here?
x = []
for i in range(3,6+1,1):
x.append([['','']] * i)
x[0][0][0] = 1
for col in x:
print col
output:
[[1, ''], [1, ''], [1, '']]
[['', ''], ['', ''], ['', ''], ['', '']]
[['', ''], ['', ''], ['', ''], ['', ''], ['', '']]
[['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', '']]
It's still an open question as to why that doesn't work... Here's a solution, though...
x = []
for i in range(3,6+1,1):
y = ['','']
tmp = []
for j in range(i):
tmp.append(y[:])
x.append(tmp)
x[0][0][0] = 1
for col in x:
print col
output:
[[1, ''], ['', ''], ['', '']]
[['', ''], ['', ''], ['', ''], ['', '']]
[['', ''], ['', ''], ['', ''], ['', ''], ['', '']]
[['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', '']]