Have You Ever Sorted A Python Dictionary By Value?

It is quite common to sort a Python dictionary based on key. But what if you want to perform sorting on the value?

In this article, I’m going to show you multiple ways to sort dictionary value and then return the resultant dictionary.

Method 1: Using operator

The very first method to sort dictionary value is by using sorted(…) function along with operator. So, let’s go ahead and import it as shown below:

import operator



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store