Find groupings of numeric subsets

Viewed 47

Lets say I have these numeric sets

a = {1, 2, 3}
b = {2, 3, 4}
c = {1, 5}

I want to find all distinct numeric groupings of the sets. The result would be

{1}, {2, 3}, {4}, {5}

My naive approach, which doesn't work, is something like this:

data = [{1, 2, 3}, {2, 3, 4}, {1, 5}]
for i in range(1, 5):
    s = set.intersection(*[x for x in data if i in x])
    print(s)

Which returns

set([1])
set([2, 3])
set([2, 3])
set([2, 3, 4])

Which could be easily de-duplicated but doesn't give the expected result.

How can I get only the groupings of numbers that exist in subset of sets?

1 Answers
Related