S
S
Sunter2021-09-14 12:58:21
Python
Sunter, 2021-09-14 12:58:21

How to turn a string into a multidimensional array?

There is a line


1 2 3
2 3 4
3 4 5
4 5 6

How to turn it into a multidimensional array of the form


Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Krostelev, 2021-09-14
@Sunter

s is your multiline string
then
a = [x.split( ' ') for x in s.split('\n')]

V
Vindicar, 2021-09-14
@Vindicar

Split first by the newline character (\n), then split each piece by space. Google the .split() and .splitlines()
line methods . Well, convert to int or float at the end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question