Sort Dictionary by Value

Sorts a dictionary by its values.

Contributed by @itsbrunodev

python
data = {"a": 3, "b": 1, "c": 2}
sorted_data = dict(sorted(data.items(), key=lambda item: item[1])) # {'b': 1, 'c': 2, 'a': 3}
GitHubEdit on GitHub