I have a (a very large) list of sets, containing pairs of values such as:
SetList = [{1,2},{2,3},{4,5},{5,6},{1,7}]
I'd like to efficiently determine the sets of values that are disjoint as implied by the transitivity of the relationships in the pairs above. For example, 1 is associated with 2, and 2 with 3 and so 1,2,3 are associated. Similarly 1 is associated with 7, so 1,2,3, and 7 are associated. In the above, 4, 5, and 6 are associated, but not with the remaining values. The result should look like the following:
DisjointSets = [{1,2,3,7},{4,5,6}]
Is there are simple, and efficient, way to perform this operation that I'm missing? Thank you!