I want to create 2 dimensional array and populate it with the following information.
n = 7
j = [0, 1, 2, 3, 4, 5, 6]
k = [0, 2, 4, 3, 3, 2, 1]
l = [0 , 46, 52, 30, 36 ,56, 40]
so, the the first list of the List L should b [0,0,0], second list of list L should be [1,2,46], third should of List L should be the list [2, 4, 52] and so on. But its not working and it keep overriding the values
#!/usr/bin/python3.6
from operator import itemgetter
n = 7
j = [0, 1, 2, 3, 4, 5, 6]
k = [0, 2, 4, 3, 3, 2, 1]
l = [0 , 46, 52, 30, 36 ,56, 40]
L = [[0]*3]*n
print(L)
x = 0
y = 0
z = 0
while x < len(j):
L[x][0] = j[x]
x = x + 1
while y < len(k):
L[y][1] = k[y]
y = y + 1
while z < len(l):
L[z][2] = l[z]
z = z + 1
print (L)
The current output is
Initialization of L, and thats ok
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
And L after modification, which is very wrong
[[6, 1, 40], [6, 1, 40], [6, 1, 40], [6, 1, 40], [6, 1, 40], [6, 1, 40], [6, 1, 40]]