I have a list of tuples:
li = [('fink', 3), ('flip', 3), ('flock', 4), ('foo', 12), ('foot', 20), ('football', 20), ('futz', 10), ('flip', 3), ('flank', 3), ('flop', 3)]
How can I sort the list by descent numbers first, and then alphabetically descend? Results:
('foot', 20) ('football', 20) ('foo', 12) ('futz', 10) ('flock', 4) ('fink', 3) ('flip', 3) ('flake', 3) ('flop', 3) from operator import itemgetter sorted_li = sorted(li, key=itemgetter(1,0), reverse=True)
While the above code is sorted in descending order, correctly, words are not sorted in alphabetical order.