Array Split twice Python

0

I need to get coordenadas cartesianas and separate them, so that you know which pair is ordered. I get a string where the points come this way: x0,y0 x1,y1 ... xn,yn I used a% w / o for space first and then an array for commas, the problem is that the way I did it is only storing array split . I need to use valor do primeiro par ordenado to traverse the entire array so that it does not matter how many points are entered Code:

pontos=vetor.split(' ')

while(cont<(2*len(pontos))):
    cord.append(0)
    cont=cont+1
cont=0
while(i<len(pontos)):
    p=(pontos[i].split(',')
        while(len(p)>cont):
           cord[cont]=p[cont]
           cord[cont+1]=p[cont+1]
           cord=cord+1
    i=i+1
    p=[]
    
asked by anonymous 04.10.2018 / 05:54

1 answer

4

One more simplified way would be:

vetor = "0,3 4,5 6,7 10,4 0,3 5,3"

coord = [list(map(int,v.split(','))) for v in vetor.split()]

print(coord)
[[0, 3], [4, 5], [6, 7], [10, 4], [0, 3], [5, 3]]
    
04.10.2018 / 07:27