Parse output to get a list in python -
this question has answer here:
- how split list evenly sized chunks? 52 answers
[u'10.57518117688789', u'43.17174576695126', u'0 10.57512669810526', u'43.17172389657181', u'0 10.57509460784044', u'43.17169116727101', u'0']
i need turn list of latitudes , longitudes in order 1st last. first element being latitude , second being longitude. don't need u or '0'.
right now, i'm printing them, method needs return list of coordinates in order.
def get_coord_list_from_earth(filename): filename = str(filename) data = xml.dom.minidom.parse(filename) coordinates = data.getelementsbytagname('coordinates')[0].firstchild.nodevalue coordinates = coordinates.strip() print coordinates.split(',')
i need output list of lists this.
[10.57518117688789, 43.17174576695126], [10.57512669810526, 43.17172389657181], [10.57509460784044, 43.17169116727101]
this link sample file need run with
could please check this:
let me know if works you:
import xml.dom.minidom def get_coord_list_from_earth(filename): filename = str(filename) data = xml.dom.minidom.parse(filename) coordinates = data.getelementsbytagname('coordinates')[0].firstchild.nodevalue coordinates = str(coordinates.strip()) lol = list() ls = coordinates.split(',') group_ls in zip(ls[0::2], ls[1::2]): f = group_ls[0].split()[-1] s = group_ls[1].split()[-1] # creating list of tuples, if not going mutate # tuple must more memory efficient list. lol.append((f,s)) return lol print get_coord_list_from_earth('test.xml')
output:
[('-99.96592053692414', '35.92662037784583'), ('-99.96540056429473', '35.92663981781373'), ('-99.96498447443297', '35.92665534578857'), ('-99.96454642236132', '35.9264185376019')]
Comments
Post a Comment