我想从给定的输入中提取纬度和经度
input=-6.00753745047,53.4988487471 -6.00649712382,53.4977981241 -6.00788849553,53.4962929888 -6.00660721705,53.4967836409
这是我尝试但没有输出的代码
for pos in range(len(input)):
lt,lo=input[pos].split(',')
print "lat is:",lt , "and long is:",lo
答案 0 :(得分:0)
如果input
真的是长字符串:
input = "-6.00753745047,53.4988487471 -6.00649712382,53.4977981241 " + \
"-6.00788849553,53.4962929888 -6.00660721705,53.4967836409"
for lt, lo in (pair.split(',') for pair in input.split()):
print "lat is:", lt, "and long is:", lo
输出:
lat is: -6.00753745047 and long is: 53.4988487471
lat is: -6.00649712382 and long is: 53.4977981241
lat is: -6.00788849553 and long is: 53.4962929888
lat is: -6.00660721705 and long is: 53.4967836409
lt
和lo
将使用此字符串值。如果您希望数值使用instread进行计算,可以使用相同的for
循环进行转换:
for lt, lo in (map(float, pair.split(',')) for pair in input.split()):
...