One option (if bad_combos should remain in the set) adds a frozenset to your set, and then checks if the pair hangs:
m1 = ('a','b') m2 = ('c','d') bad_combos = set() bad_combos.add(frozenset([m1,m2])) (m2, m1) in bad_combos # False frozenset([m2, m1]) in bad_combos # True
this, of course, retains the complexity of O (1) for membership testing.
Another option (if the set is optional) includes switching to a list as the storage data structure and adding pairs of pairs to it:
m1 = ('a','b') m2 = ('c','d') bad_combos = [] bad_combos.append({m1,m2}) #((a,b),(c,d)) if {m2,m1} in bad_combos: print("Found") else: print("Not Found")
this, of course, leads to O (n) membership testing.
source share