↻
⏵︎ Run
list_ = [('Saranya',84), ('Surya',92) , ('Joy',88) , ('Sree',86), ('Ritha',89)] #sort by second element of tuple ith = 0 list_length = len(list_) for i in range(0, list_length): for j in range(0, list_length-i-1): if (list_[j][ith] > list_[j + 1][ith]): temp = list_[j] list_[j]= list_[j + 1] list_[j + 1]= temp print(list_)
Output