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