0

If I input an arbitrary amount of points [x1,y1].....[xn,yn] into a function I need to somehow return/print the shortest distance between all of the points. I understand how to find the distance between two points (fairly easy and straight forward), but how do I take an arbitrary amount of points and test each point with one another without testing each point with itself.

3
Contributors
2
Replies
18
Views
3 Years
Discussion Span
Last Post by vegaseat
0

Hint ...

import itertools as it

# create non-repeating pairs
print(list(it.combinations('ABCD', 2)))

''' result ...
[('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')]
'''

Note:
Instead of 'ABCD' use a sequence of (x, y) coordinate points.

Edited by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.