I have a data tree with multiple branches where each branch contains a list of numbers. I would like to identify which of the branches are similar. Two branches would be similar if one of them has at least 50% (or any other arbitrary number/percent) of the same numbers as the other branch. The lists could have a different length, the order of the list does not matter, lists contain only unique numbers. For example we have three branches with the following numbers:

1, 2, 3

2, 5, 4

3, 4, 1

Branches one and three would be similar as they both contain the numbers 1 and 3. Branch 2 is not similar to any other branch, as it only contains 1 matching number with either of the two other branches.

If anyone has a way of implementing this, then I would be very grateful. Sorry for the shitty branch numbers. Similar branches.gh (4.0 KB)

Here is a C# code to perform such an analysis.
Two lists are considered similar if the ratio (nb of common values)/(maximum list count) is greater or equal to the similarity coefficient.

My first appraoch was to loop twice and compare a new candidate to all lists already stored in a â€śsimilarâ€ť set. But with 50% similarity, all lists ended up being in the same set.
So this can be disabled with the compareToAll input, where candidates are only compared to the first list of the set.

Edit : just realized it was better to include a new candidate in a set if it was similar to ALL existing lists in the set, not just one of them. This gives 4 groups. Added check with Text Join.