In this python tuple program, we will extract tuples that are symmetrical with others from a list of tuples.
Steps to solve the program
l = [('a','b'),('d','e'),('b','a')]
print("Original list of tuples: ",l)
temp = set(l) & {(b, a) for a, b in l}
sym = {(a, b) for a, b in temp if a < b}
print("Tuples that are symmetric: ",sym)
Output :
Original list of tuples: [('a', 'b'), ('d', 'e'), ('b', 'a')]
Tuples that are symmetric: {('a', 'b')}