I’m trying to do something like a medals tally ranking with Lists in python. I have a List which keeps growing. Each element in the list is a list with four elements.
eg: L = [[0,1,2,3],[3,0,6,2]]
I’m trying to rank the elements in this list such that the result turns out to be(for the above eg):
L = [[3,0,6,2],[0,1,2,3]] i.e. something like a medals tally where the first element in the inner list is gold, second is silver etc
Is there a simple way to do this in python ?
You can just use the built-in, sorted
[Edit: The above will rank by total number of golds, then number of silvers, etc. This seems to be the most common way to rank metals (see Metal Tally here). You could also define your own function, and use the cmp keyword to rank them a different way.]