0

I am trying to assign a string to a matrix. So "ABCDEFGHI" will become [[a",'b','c'],['d','e','f'],['g','h','i']], below is the code I wrote. I spent a few hours on this and I have no idea why this is not working: (The code below is in python)

input = "ABCDEFGHI"

matrix = [[0]*3]*3

index = 0
for i in range(3):
    for j in range(3):
        matrix[i][j] = input[index]
        index += 1


print(matrix)

I am trying to assign a string to a matrix. So "ABCDEFGHI" will become [[a",'b','c'],['d','e','f'],['g','h','i']], below is the code I wrote. I spent a few hours on this and I have no idea why this is not working:

The expected output is [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']], but the actual output is [['G', 'H', 'I'], ['G', 'H', 'I'], ['G', 'H', 'I']]

Jacky Liu
  • 1
  • 1

0 Answers0