Q:

Clean way to parse a string (bunch of coordinates) into a list of floats in python?

I was writing code that was looking uglier and uglier to take this string:
"69.766357,21.026979 70.303459,14.286892 71.782379,15.119740 71.216835,22.351538"

and parse it into a list that looked like this:
pos = [[69.766357,21.026979],[70.303459,14.286892],[71.782379,15.119740],[71.216835,22.351538],[69.766357,21.026979]]

Latest code:
#shave off the first point because we need to add it back in to close poly
firstVal = elem.text.split()
firstVal = firstVal[0].split(',')

for i in elem.text.split():
    smallList = []
    for j in i.split(','):
        smallList.append(float(j))                      
    finalVals.append(smallList)

smallList=[]
smallList.append(float(firstVal[0]))
smallList.append(float(firstVal[1]))
finalVals.append(smallList)

print finalVals

This is the best I could come up with.

A:

There is a clean pythonic way for what you are looking for, called list comprehension explained here
you need to do two list comprehensions for what you need as below:
pos_string = "69.766357,21.026979 70.303459,14.286892 71.782379,15.119740 71.216835,22.351538"
pos = []
pos = [[float(lat_long) for lat_long in position.split(',')] for position in pos_string.split(' ')]

A:

test = "69.766357,21.026979 70.303459,14.286892 71.782379,15.119740 71.216835,22.351538"

print([[float(j) for j in i.split(',')] for i in test.split()])

