I have input like this
JavaScript
x
2
1
logs = ['88 99 200','88 99 300','99 32 100','12 12 15']
2
How to convert it into an array of array in Python like this?
JavaScript
1
2
1
logs = [[88 99 200],[88 99 300],[99 32 100],[12 12 15]]
2
Advertisement
Answer
Use str.split
with map
:
JavaScript
1
9
1
list(map(str.split, logs))
2
3
4
Out[36]:
5
[['88', '99', '200'],
6
['88', '99', '300'],
7
['99', '32', '100'],
8
['12', '12', '15']]
9
If you want to convert each item to int
:
JavaScript
1
5
1
list(map(lambda x: [int(i) for i in x], map(str.split, logs)))
2
3
4
Out[37]: [[88, 99, 200], [88, 99, 300], [99, 32, 100], [12, 12, 15]]
5