I\'m looking for an efficient way to calculate the rank vector of a list in Python, similar to R\'s rank function. In a simple list with no ties between the ele
rank
[sorted(l).index(x) for x in l]
sorted(l) will give the sorted version index(x) will give the index in the sorted array
sorted(l)
index(x)
index
for example :
l = [-1, 3, 2, 0,0] >>> [sorted(l).index(x) for x in l] [0, 4, 3, 1, 1]