I am trying to enter elements in a 2d string matrix in python of 3 rows and 2 colums. I am trying to access the space of the first row and first column arr[0][0]. When I am inserting an element in the arr[0][0] position the same element is being inserted in arr 1[0] and arr[2][0] position. How to access one position at a time. Please help. The code snippet is given below
arr = [['']*2]*3
print(arr)
arr[0][0] = 's'
print(arr)
The output is given below:
EDIT : Changing the declaration from the one mentioned in the code snippet to the one given below works perfectly.
arr = [['']*2 for _ in range(3)]
Shared it just incase somebody is facing the same problem and couldn't find the right question.