Uncategorized

for loop – Python matrix input not working this way?


I have tried several ways that are working. But, this one is not.
Please help me understand why ?

row, col = 2, 3
mat1 = [[None]*col]*row
print(mat1)
for i in range(0, row):
    for j in range(0, col):
        mat1[i][j] = int(input())
print(mat1)

Input:

1
2
3
4
5
6

Expected:

[[1,2,3], [4,5,6]]

Getting:

[[4,5,6], [4,5,6]]



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *