A
A
argeo052019-12-20 18:28:54
Python
argeo05, 2019-12-20 18:28:54

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

2 answer(s)
R
Rais, 2019-12-20
@0pauc0

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.

V
Vladimir Kuts, 2019-12-20
@fox_12

2D array example

str1 = '''21 312 21
25 412 13'''

arr = [x.split(' ') for x in str1.split('\n')]
print(arr)


convert array values ​​to numbers - will be your homework

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question