# How to take a list and build sets of 2 elements without duplicates?

I am new to Mathematica so the answer to this question is probably easy.

I have a list of 2D-points in the form {{x1, y1}, {x2, y2}, ...} Then I have a function that will take two points and test some condition based on their distance. I want to test all points against each other, without duplicates.

How can you do that?

• Look up DistanceMatrix[]. "Without duplicates" means you'll only need the strict upper triangle of that matrix. – J. M. will be back soon Jun 25 '16 at 17:28
• What about yourCondition/@yourDistanceFunction@@@Permutations[list]? – JungHwan Min Jun 25 '16 at 17:31
• Following @J.M. 's solution, UpperTriangularize[] would be appropriate to use with DistanceMatrix[]. – JungHwan Min Jun 25 '16 at 17:34
• EuclideanDistance @@@ Subsets[yourList, {2}] – yode Jun 25 '16 at 17:34
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jun 25 '16 at 17:39

Based on comment from yode

Let us suppose a list:

list = {{1, 1}, {2, 1}, {7, 8}, {8, 9}}


$\left( \begin{array}{cc} 1 & 1 \\ 2 & 1 \\ 7 & 8 \\ 8 & 9 \\ \end{array} \right)$

With this function you can calculate the distances of each point without repetitions:

EuclideanDistance @@@ Subsets[list, {2}]


$\left\{1,\sqrt{85},\sqrt{113},\sqrt{74},10,\sqrt{2}\right\}$

Here below only a presentation of the steps

EuclideanDistance[list[], list[]]


$1$

EuclideanDistance[list[], list[]]


$\sqrt{85}$

EuclideanDistance[list[], list[]]


$\sqrt{113}$

EuclideanDistance[list[], list[]]


$\sqrt{74}$

EuclideanDistance[list[], list[]]


$10$

EuclideanDistance[list[], list[]]


$\sqrt{2}$