How to sort a list of tuples by the second value in Python

Sorting a list of tuples by the second value will reposition the tuples position in the list so that the tuples second values are in ascending order. For instance, [(10, 3),(20, 1)] sorted by the second value becomes [(20, 1), (10, 3)]

Solution for How to sort a list of tuples by the second value in Python : You can use a lambda function as an argument to sort() to sort a list of tuples by the second value Call list.sort(key=None) with list as a list of tuples and key set to lambda x: x[1] to sort list by the second element of each tuple.


how-to-sort-a-list-of-tuples-by-the-second-value-in-python