I need to take a list I have created and find the closest two points and print them out. How can I go about comparing each point in the list?
There isn\'t any need to pl
First, some notes:
a**2 # squares a
(xi - xii)**2 # squares the expression in parentheses.
mInput doesn't need to be declared in advance.
fList.append((x, y))
is more pythonic than using +=
.
Now you have fList
. Your distance function can be rewritten to take 2 2-tuple (point) arguments, which I won't bother with here.
Then you can just write:
shortest = float('inf')
for pair in itertools.combinations(fList, 2):
shortest = min(shortest, distance(*pair))