First of all, apologies if this too naive (I am a beginner). I have the following type of list of lists, which I would like to first sort by the last member of the inner li
>>> data = [[1, .45, 0], [2, .49, 2], [3, .98, 0], [4, .82, 1], [5, .77, 1], [6, .98, 2] ]
>>> sorted(data, key=lambda x:(x[2], -x[1]))
[[3, 0.98, 0], [1, 0.45, 0], [4, 0.82, 1], [5, 0.77, 1], [6, 0.98, 2], [2, 0.49, 2]]
You can add extra terms to the lambda as required
You can pass sorted multiple keys:
data = [[1, .45, 0], [2, .49, 2], [3, .98, 0], [4, .82, 1], [5, .77, 1], [6, .98, 2] ]
sorted(data, key=lambda x: (x[2], -x[1]))
[[3, 0.98, 0],
[1, 0.45, 0],
[4, 0.82, 1],
[5, 0.77, 1],
[6, 0.98, 2],
[2, 0.49, 2]]