Answer the question
In order to leave comments, you need to log in
Inputting data into a two dimensional array in python?
A matrix is given as a sequence of rows ending with a row containing only the string "end" (without quotes) for example:
21 312 21
25 412 13
end
how to write this into a two-dimensional array a?
Answer the question
In order to leave comments, you need to log in
Read lines, if the line is equal to 'end' then finish, otherwise split the line into parts by space, arrange the numbers in the list of lists.
2D array example
str1 = '''21 312 21
25 412 13'''
arr = [x.split(' ') for x in str1.split('\n')]
print(arr)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question