Find duplicate sets in list of sets

You could use frozenset and Counter, for example, like this:

from collections import Counter

lst = [{7, 12, 16, 17, 31}, {33, 4, 8, 10, 46}, {6, 40, 43, 22, 29}, {2, 35, 9, 41, 31}, {34, 38, 42, 43, 45},
        {38, 16, 20, 25, 30}, {2, 10, 45, 19, 25}, {4, 44, 41, 14, 16}, {39, 40, 16, 25, 28}, {34, 37, 45, 19, 23},
        {4, 41, 44, 14, 16}]

counts = Counter(frozenset(s) for s in lst)

print([e for e, c in counts.items() if c > 1])

Output

[frozenset({16, 4, 41, 44, 14})]

As a side note, avoid using list as a name, it shadows the built-in list.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top