0
How to get matxix input using map in python
First we want to give the n*m value like 3 3 And we want to get the 9 value input like 4 0 0 0 4 0 0 0 4
2 Answers
+ 3
Hi, I don't think you need to define the n*m dimension of the array in advance, just use a while loop to input the values. Use input() and split() with the separator you use for the values. In the same expression use map with int and finally put all in a temporary list().
Append this part of the input to the final list, ask the user if he will continue or break.
So if you input:
1,2,3
It will turn this to a list with: [1,2,3].
Repeate this until you have all of your values:
[[1,2,3],[4,5,6],[7,8,9]]
+ 1
What does the input look like ?