How to get matxix input using map in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

14th Nov 2019, 12:26 PM
SRIRAM P
SRIRAM P - avatar
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]]
14th Nov 2019, 1:12 PM
Lothar
Lothar - avatar
+ 1
What does the input look like ?
14th Nov 2019, 12:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar