Sort a dictionary by its values
sorted(d.items(), key=lambda x: x[1], reverse=True)
The above line will returns a list of tuples (since we are sorting the d.items()
), and will not change the orders within the dictionary. We need an assigment, and a dict()
function to rewrite.