Python tuple program to sort a list if tuples by the minimum value of a tuple

In this python tuple program, we will sort a list if tuples by the minimum value of a tuple.

Steps to solve the program
  1. Take a list of tuples as input.
  2. Use sorted() to sort the tuple and pass the lambda function to sort the tuple by the minimum value to the key inside the sorted().
  3. Print the output.
				
					l = [(1,5,7),(3,4,2),(4,9,0)]
print("Original list of tuples: ",l)
l1 = sorted(l,key = lambda x: min(x))
print("After sorting: ",l1)
				
			

Output :

				
					Original list of tuples:  [(1, 5, 7), (3, 4, 2), (4, 9, 0)]
After sorting:  [(4, 9, 0), (1, 5, 7), (3, 4, 2)]
				
			

sort a tuple by the maximum value of a tuple.

concatenate two tuples.

Leave a Comment