S
S
sharkyyy32020-05-25 14:22:10
Python
sharkyyy3, 2020-05-25 14:22:10

How to split 1 list by 2?

There is a list:

points = ["42.07, 48.29", "42.81, 132.87", "42.82, 47.12", "42.88, 47.64", "42.98, 47.5"]

I need to split it into two lists so it looks like this:
point1 = ["42.07", "42.81", "42.82", "42.88", "42.98" ]
point2 = ["48.29", "132.87", "47.12", "47.64" ,"47.5"]

How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2020-05-25
@sharkyyy3

points = ["42.07, 48.29", "42.81, 132.87", "42.82, 47.12", "42.88, 47.64", "42.98, 47.5"]
point1, point2 = list(), list()

for point in points:
    p1, p2 = point.split(',')
    point1.append(p1.strip())
    point2.append(p2.strip())

0
0xD34F, 2020-05-25
@0xD34F

point1, point2 = map(list, zip(*[ n.split(', ') for n in points ]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question