Find common elements between two lists of tuples

In this python tuple program, we will find common elements between two lists of tuples.

Steps to solve the program
  1. Take two lists of tuples as input.
  2. Create a set of two lists to remove duplicate tuples by using set().
  3. Find the common tuples between two lists of tuples using the ” operator.
  4. Print the output.
				
					tup1 = [(1,5),(4,8),(3,9)]
tup2 = [(3,9),(5,6),(1,5),(0,4)]
print(f"Tuples: {tup1} and {tup2}")
result = (set(tup1) & set(tup2))
print("Common elements between tuples: ",result)
				
			

Output :

				
					Tuples: [(1, 5), (4, 8), (3, 9)] and [(3, 9), (5, 6), (1, 5), (0, 4)]
Common elements between tuples:  {(3, 9), (1, 5)}
				
			

order tuples by external list.

convert a binary tuple to an integer.

Leave a Comment