Use sorted with a custom key function
Instead of using lamda you can also use itemgetter from the operator module
data = [[0, False, "c"], [0, True, "z"], [1, False, "P"], [0, True, "A"]] sorted_data = sorted(data, key=lambda x: x[1], reverse=True) print(sorted_data)
Output:[[0, True, 'z'], [0, True, 'A'], [0, False, 'c'], [1, False, 'P']]
Instead of using lamda you can also use itemgetter from the operator module
from operator import itemgetter data = [[0, False, "c"], [0, True, "z"], [1, False, "P"], [0, True, "A"]] sorted_data = sorted(data, key=itemgetter(1), reverse=True) print(sorted_data)