I want to create a random size list in Python.
Here's my code:
row_num = int(input('Please enter matrix row number:'))
colum_num = int(input('please enter matrix column number:'))
a = [[0]*row_num]*colum_num
print("Please enter matrix: ")
for i in range(colum_num):
for j in range(row_num):
a[i][j]=int(input())
print(a)
For example, I want to generate a 2*3 matrix, here's my outcome:
Please enter matrix row number:2
please enter matrix column number:3
Please enter matrix:
1
2
3
4
5
6
[[5, 6], [5, 6], [5, 6]]
I expect the result to be [[1,2],[3,4],[5,6]].
Why is the result the last element?