how to find sort values in a dictionary python code example
Example 1: sort dictionary by values
from collections import OrderedDict
dd = OrderedDict(sorted(d.items(), key=lambda x: x[1]))
print(dd)
Example 2: sorting a dictionary by value in python
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
{k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}