I want to sort, let's say, this list:
[('alpha', 2), ('delta', 3), ('charlie', 3), ('tango', 1), ('foxtrot', 1), ('echo', 2)]
The result should be
[('charlie', 3), ('delta', 3), ('alpha', 2), ('echo', 2), ('foxtrot', 1), ('tango', 1)]
charlie is first because it has the largest number, and it's ahead of delta because c alphabetically comes before d (so if the numbers are the same it sorts those specific ones alphabetically). alpha is ahead of echo because even though they have the same number, a alphabetically comes before e. echo is ahead of foxtrot because echo has the larger number, and foxtrot is ahead of tango even though they have the same number because f comes before t.
Currently my method involves a while loop (which moves the item to the right spot) inside of a for loop (which looks at every element), with another loop afterwards that does the same thing if the number is the same so it can sort alphabetically.
Is there a better method of doing this?