First read the data into a list of lists then call a function.
with open("file.txt","r") as f:
a = [map(int,l.split()) for l in f if l.split()]
dist(a)
a
[[1, 5, 10], [2, 8, 20], [3, 9, 5], [4, 3, 10]]
then by using the itertools combinations()
function, you get all the node pairs.
def dist(data):
comb = list(combinations([b[0] for b in data],2))
comb
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
Then is a matter of iterate through the list and get the points for input
for (x,y) in comb:
x1 = data[x-1][1]
x2 = data[y-1][1]
y1 = data[x-1][2]
y2 = data[y-1][2]
d = sqrt((x2-x1)**2 + (y2-y1)**2)
print "{}-{} dis = {}".format(x,y,d)
Which outputs:
1-2 dis = 10.4403065089
1-3 dis = 6.40312423743
1-4 dis = 2.0
2-3 dis = 15.0332963784
2-4 dis = 11.1803398875
3-4 dis = 7.81024967591