d = {}
d[frozenset((1, 2))] = 'something'
s = frozenset((2, 1))
if s in d:
    print('(2, 1) is in the dict')
else:
    print('not found')
Look up a tuple in a python dictionary matching (x,y) or (y,x)