In this python tuple program, we will sort a list if tuples by the minimum value of a tuple.
Steps to solve the program
- Take a list of tuples as input.
- 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().
- 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)]