I have a list of tuples, namely [(7, 14), (3, 12), (20, 22), (6, 14), (2, 12)].
I want to sort it by the second value in the tuple, but if the second values are the same, I want the earlier element in a sorted list to be with the lower first value. For more clarity (6,14) should be earlier in the sorted list, then (7, 14).
Right now I have the following code:
result = [(7, 14), (3, 12), (20, 22), (6, 14), (2, 12)]
result.sort(key = lambda a: a[1])
Output[]: [(3, 12), (2, 12), (7, 14), (6, 14), (20, 22)]
What I want is:
Output[]: [(2, 12), (3, 12), (6, 14), (7, 14), (20, 22)]