How to find all symmetric pairs in a list of pairs with Python

1 Answer

0 votes
def findPairs(pairs):
    st = set()
 
    for (x, y) in pairs:
        st.add((x, y))
 
        if (y, x) in st:
            print((x, y), "-", (y, x))
 
 
pairs = [(7, 2), (1, 8), (5, 1), (9, 3), (2, 7), (1, 5), (4, 6)]

findPairs(pairs)
 


'''
run:

(7, 2), (1, 8), (5, 1), (9, 3), (2, 7), (1, 5), (4, 6)
 
'''

 



answered Aug 6, 2022 by avibootz

Related questions

...