如何从for循环中获取输出到python中的单独集合?

时间:2017-07-07 06:16:12

标签: arrays loops for-loop output python-3.6

所以我需要将程序中的距离的所有输出放在一个集合中,以便我可以对它执行操作。这是代码,大多数计算都无关紧要。 Python 3.6。

import json

with open('strings.json') as data_file:    
    data = json.load(data_file)

from math import sin, cos, sqrt, atan2, radians


R = 6373.0

for i in range(0, 81):
    dataPoint = data[i]
    dataPoint1 = data [i+1]
    coordinate = dataPoint['coordinates']
    coordinate1 = dataPoint1['coordinates']
x = coordinate[0]
y = coordinate[1]
x1 = coordinate1[0]
y1 = coordinate1[1]
#Irrelevant math here
import math
lat1 = math.cos(math.radians(x)) #converts degrees of long or latitude into rads

lon1 = math.cos(math.radians(y))
lat2 = math.cos(math.radians(x1))
lon2 = math.cos(math.radians(y1))
dlon = lon2 - lon1
dlat = lat2 - lat1

a = sin(dlat / 2)**2 +  cos(lat1) * cos(lat2) * sin(dlon / 2)**2  #formula for distance
c = 2 * atan2(sqrt(a), sqrt(1 - a))

这就是问题所在 -

distance = R * c
SetDist = [distance]      #this gives me just the final value of distance 
                          from the iteration, I need all.

print("distance between the 2 points:", distance) 

我还会在循环块外部打印该组。感谢。

0 个答案:

没有答案