I have a python dictionary:
x = {\'a\':10.1,\'b\':2,\'c\':5}
How do I go about ranking and returning the rank value? Like getting back:
You could do like this,
>>> x = {'a':10.1,'b':2,'c':5} >>> m = {} >>> k = 0 >>> for i in dict(sorted(x.items(), key=lambda k: k[1], reverse=True)): k += 1 m[i] = k >>> m {'a': 1, 'c': 2, 'b': 3}