Assuming I have a the a list of 9 items, I want to convert it into a list of 3 by 3 items
from [1,2,3,4,5,6,7,8,9] -> [[1,2,3],[4,5,6],[7,8,9]]
this is the code:
def main():
L = range(1,10)
twoD= [[0]*3]*3 #creates [[0,0,0],[0,0,0],[0,0,0]]
c = 0
for i in range(3):
for j in range(3):
twoD[i][j] = L[c]
c+=1
for some reason this returns
twoD = [[7, 8, 9], [7, 8, 9], [7, 8, 9]]
and I have no clue why, what is making it do this?