Python Program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
def last(n):
return n[-1]
def sort(tuples):
return sorted(tuples, key=last)
a=input("Enter a list of tuples:")
print("Sorted:")
print(sort(a))
Output
Enter a list of tuples:[(2,5),(1,2),(4,4),(2,3)]
Sorted:
[(1, 2), (2, 3), (4, 4), (2, 5)]
