python - Iterating over string to create array of Lat Long coordinates -
elements of list represent pairs of x , y decimal degree coordinates space between respective x , y coordinates formatted strings:
'34.894127 29.761515', '32.323574 30.166336', '32.677296 31.961439', '35.298668 31.559237', '34.894127 29.761515
thus far can pick out first element , set x value:
x = mystring[0:mystring.find(' ')]
how can iterate on string make array consisting of pairs of x , y coordinates string?
where mystring = mystring = "'34.894127 29.761515', '32.323574 30.166336', '32.677296 31.961439', '35.298668 31.559237', '34.894127 29.761515"
list of pairs so:
x = [pair.lstrip().strip("'").split(' ') pair in mystring.split(',')] # gives: [['34.894127', '29.761515'], ['32.323574', '30.166336'], ['32.677296', '31.961439'], ['35.298668', '31.559237'], ['34.894127', '29.761515']]
or if want tuples:
x = tuple([tuple(pair.lstrip().strip("'").split(' ')) pair in mystring.split(',')]) # gives: (('34.894127', '29.761515'), ('32.323574', '30.166336'), ('32.677296', '31.961439'), ('35.298668', '31.559237'), ('34.894127', '29.761515'))
Comments
Post a Comment