Extract tuples that are symmetrical with others from a list of tuples

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')}
				
			

convert a list of lists to a tuple of tuples.

return an empty set if no tuples are symmetrical.

Leave a Comment