Best Answer · By JanBask Python Expert
Answered on Mar 2, 2021
To sort (list/tuple) of lists/tuples by the element at a given index you can use the following pieces of codes:-
sorted_by_second = sorted(data, key=lambda tup: tup[1])
or:
data.sort(key=lambda tup: tup[1]) # sorts in place