I would like to know a short method to input the elements of a 2D matrix one by one. (Using only default python modules)
My current code:
i= []
for x in range(3):
i.append(map(int, raw_input("enter the element").split()))
for y in range(3):
i.append(map(int, raw_input("enter the element").split()))
print i
I want the result to be like :
[[1,2,3],
[4,5,6],
[7,8,9]]
But end up getting:
[[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12]]
I have already checked for potential duplicates, but could not find any that would take each and every element of the matrix.
Any short method would be appreciated.
EDIT: The rows and columns should be changeable separately. So, if we enter 3 rows and 4 columns, the elements should be automatically placed into their respective locations.
Example: For a 2x2 matrix
If the input is: 1,2,1,2
Then the matrix should be :
[[1,2],
[1,2]]