How to sort a list/tuple of lists/tuples by the element at a given index?
For sorting by multiple criteria, namely for instance by the second and third elements in a tuple, let
data = [(1,2,3),(1,2,1),(1,1,4)]
and so define a lambda that returns a tuple that describes priority, for instance
sorted(data, key=lambda tup: (tup[1],tup[2]) )[(1, 1, 4), (1, 2, 1), (1, 2, 3)]