I want to sort the list of list based on the two factors:
- PRIMARILY: list has to be sorted in ascending order based on the second element of each list in the list
- If there are cases wheres various list has same second elements then for those particular lists sorting has to be done in ascending order based on first element.
data_input: [ [78, 10], [130, 0], [10, 1], [100, 100], [2, 2], [1, 99], [100, 0] ]
for sorting based on first criterion I am using this code
data_input.sort(key= lambda x: x[1])
but cannot think of any way to implement second criterion as well
Desired output :
- data_input: [ [100, 0], [130, 0], [10, 1], [2, 2], [78, 10], [1, 99], [100, 100] ]*