How ro read mutli lined input into 2d arrays in python

1684 views python
3

I've been across a problem in python, the input format of the 2d array to be read is

3           # number of rows and columns of a square matrix
1 2 3 4     # first row 
3 4 6 9     # second row
4 6 3 1     # third row

how do I read 2d array from the console like the above

Python Version : 3.6

IDE : Spyder (Python 3.6)

answered question

1 Answer

11

n = int(input())
dicta = dict()
for i in range(n):
    dicta["var"+str(i)] = input()

this take the number of lines input you want makes a dictionary with the number of inputs you initialy said

posted this

Have an answer?

JD

Please login first before posting an answer.