I was given an array of strings and I want to split each of the individual strings into separate characters and store them in a separate 2-D array. I wrote the following code:-
# The given array
grid = ['1112', '1912', '1892', '1234']
# Creating a new 2D array
mat = [[None]*len(grid)]*len(grid)
for i in range(0,len(grid)):
for j in range(0,len(grid)):
mat[i][j] = grid[i][j]
print(mat)
But doing this gives weird values in my two-dimensional array, mat. Each of the row of the 2D array mat gets printed as ['1','2','3','4'] but this should be the value of the last row only.
I shall be thankful if someone could answer my query.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…