I have this output: [(3, \'one\'), (2, \'was\'), (2, \'two\'), (1, \'too\'), (1, \'racehorse\'), (1, \'a\')]
[(3, \'one\'), (2, \'was\'), (2, \'two\'), (1, \'too\'), (1, \'racehorse\'), (1, \'a\')]
and i need to make it so that the tupl
You can use list.sort with the reverse argument:
>>> l = [(3, 'one'), (2, 'was'), (2, 'two'), (1, 'too'), (1, 'racehorse'), (1, 'a')] >>> l.sort(key=lambda x: x[1], reverse=True) >>> l.sort(key=lambda x: x[0]) >>> l [(1, 'too'), (1, 'racehorse'), (1, 'a'), (2, 'was'), (2, 'two'), (3, 'one')]