A nested list,
A = [[2, 0], [1, 0], [4, 3], [3, 2], [5, 1]]
I am trying to sort it based on the 1st element in ascending order, i.e
result_A = [[2, 0], [1, 0], [5, 1], [3, 2], [4, 3]]
When the 1st element is common in any of the nested lists, I am trying to sort it based on the 0th element. So,
required_A = [[1, 0], [2, 0], [5, 1], [3, 2], [4, 3]]
This is my code so far:
required_A = sorted(A, key=itemgetter(1))
I am able to sort it based on the 1st element, but am clueless how to sort it again on the 0th element without the remaining order getting messed up. Thanks!
sorted(A, key=lambda x: x[::-1])