I am having problems with tuples. I have a list of tuples that have (x,y,z) coordinates. Each coordinate is a float. How can I calculate the distance between two coordinates? Can you do this with tuples?

coord=[]
for line in CN_list:
	x=line[30:39]
	y=line[38:47]
	z=line[46:55]
	coord.append((float(x),float(y), float(z)))

Sure you can. The code looks something like this (done in a hurry):

import math
s = (1,2,3)
t = (5,5,5)

x0 = (s[0]-t[0])**2
x1 = (s[1]-t[1])**2
x2 = (s[2]-t[2])**2

print math.sqrt(x0+x1+x2)

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.