How to sort list of tuple according to first value in tuple
# Python program to sort a list of
# tuples by the second Item using sort()
# Function to sort hte list by first item of tuple
def Sort_Tuple(tup):
# reverse = None (Sorts in Ascending order)
# key is set to sort using second element of
# sublist lambda has been used
tup.sort(key = lambda x: x[0])
return tup
# Driver Code
tup = [(10,'rishav'), (5, 'akash'), (20 , 'ram'), (15 , 'gaurav')]
# printing the sorted list of tuples
print(Sort_Tuple(tup))