I have a list of tuples: [(2, Operation.SUBSTITUTED), (1, Operation.DELETED), (2, Operation.INSERTED)]
[(2, Operation.SUBSTITUTED), (1, Operation.DELETED), (2, Operation.INSERTED)]
I would like to sort this list in 2 ways:
You can use this:
from operator import itemgetter d = [(1, 'DELETED'), (2, 'INSERTED'), (2, 'SUBSTITUTED')] d.sort(key=itemgetter(1),reverse=True) d.sort(key=itemgetter(0)) print(d)