Let's say we have a list, and we want to generate a ranking of the list, with the smallest value being 1 in the resulting list. Say the list is [4,4,3], which contains duplicates. So, when duplicates occur, we will replace the repeated elements with the permutation of the repeated elements.
In this case, the repeated element is 2.
So, the result should be [[3,2,1],[2,3,1].
I currently have a naive implementation by repeatedly finding the largest element:
def naive(lst):
size = len(lst)
rst = [None] * size
for i in range(size):
max_elt = max(lst)
max_index = lst.index(max_elt)
rst[max_index] = size-i
lst[max_index] = 0
return rst
This returns a single result [3, 2, 1].
Also, what if the list contains multiple duplications, e.g. [2,2,4,4]?