The sorted() function takes a key= parameter

newlist = sorted(list_to_be_sorted, key=lambda d: d['name'])

Alternatively, you can use operator.itemgetter instead of defining the function yourself

from operator import itemgetter
newlist = sorted(list_to_be_sorted, key=itemgetter('name'))

For completeness, add reverse=True to sort in descending order

newlist = sorted(list_to_be_sorted, key=itemgetter('name'), reverse=True)
Answer from Mario F on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org › news › sort-dictionary-by-value-in-python
Sort Dictionary by Value in Python – How to Sort a Dict
September 13, 2022 - That’s because Python doesn’t have an inbuilt method to do it. However, I figured out a way to sort dictionaries by value, and that’s what I’m going to show you how to do in this article. ... The sorted() method sorts iterable data such as lists, tuples, and dictionaries.
🌐
w3resource
w3resource.com › python-exercises › dictionary › python-data-type-dictionary-exercise-1.php
Python: Sort (ascending and descending) a dictionary by value - w3resource
June 28, 2025 - # The result is a list of sorted ... sorted list of key-value pairs back into a dictionary. # The 'reverse=True' argument sorts the list in descending order by value....
🌐
GeeksforGeeks
geeksforgeeks.org › python › sort-dictionary-by-value-python-descending
Sort Dictionary by Value Python Descending - GeeksforGeeks
July 23, 2025 - In this example, the dictionary `my_dict` containing subject grades is sorted in descending order based on values using a dictionary comprehension with a lambda function as the sorting key, resulting in the `sorted_dict` displaying subjects ...
🌐
Real Python
realpython.com › sort-python-dictionary
Sorting a Python Dictionary: Values, Keys, and More – Real Python
December 14, 2024 - Yes, you can sort a Python dictionary in descending order by passing reverse=True to the sorted() function.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › sort list of dictionaries by value in python?
Sort List of Dictionaries by Value in Python? - Spark By {Examples}
May 31, 2024 - We can sort a list of dictionaries by value using sorted() or sort() function in Python. Sorting is always a useful utility in everyday programming. Using sorted() function we can sort a list of dictionaries by value in ascending order or descending ...
🌐
DataCamp
datacamp.com › tutorial › sort-a-dictionary-by-value-python
How to Sort a Dictionary by Values in Python | DataCamp
June 19, 2024 - The .sorted() function will sort the values alphabetically in ascending or descending order, just as it does with numbers. A2: To sort a dictionary with nested dictionaries, we need to define a custom sorting function that extracts and compares ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sort-python-dictionaries-by-key-or-value
Sort Python Dictionary by Key or Value - Python - GeeksforGeeks
Let's explore different methods to sort dictionary by key or value in Python. 1. Using sorted() with lambda: This method sorts the dictionary efficiently by its values using the sorted() function and a lambda expression.
Published   January 13, 2026
🌐
Better Stack
betterstack.com › community › questions › how-to-sort-list-of-dictionaries-in-python
How do I sort a list of dictionaries by a value of the dictionary in Python? | Better Stack Community
January 26, 2023 - If you want to sort the list in descending order, you can pass the reverse=True argument to the sorted() function: ... This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Find elsewhere
Top answer
1 of 16
7095

Python 3.7+ or CPython 3.6

Dicts preserve insertion order in Python 3.7+. Same in CPython 3.6, but it's an implementation detail.

>>> 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}

or

>>> dict(sorted(x.items(), key=lambda item: item[1]))
{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}

Older Python

It is not possible to sort a dictionary, only to get a representation of a dictionary that is sorted. Dictionaries are inherently orderless, but other types, such as lists and tuples, are not. So you need an ordered data type to represent sorted values, which will be a list—probably a list of tuples.

For instance,

import operator
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=operator.itemgetter(1))

sorted_x will be a list of tuples sorted by the second element in each tuple. dict(sorted_x) == x.

And for those wishing to sort on keys instead of values:

import operator
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=operator.itemgetter(0))

In Python3 since unpacking is not allowed we can use

x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=lambda kv: kv[1])

If you want the output as a dict, you can use collections.OrderedDict:

import collections

sorted_dict = collections.OrderedDict(sorted_x)
2 of 16
1648

As simple as: sorted(dict1, key=dict1.get)

Well, it is actually possible to do a "sort by dictionary values". Recently I had to do that in a Code Golf (Stack Overflow question Code golf: Word frequency chart). Abridged, the problem was of the kind: given a text, count how often each word is encountered and display a list of the top words, sorted by decreasing frequency.

If you construct a dictionary with the words as keys and the number of occurrences of each word as value, simplified here as:

from collections import defaultdict
d = defaultdict(int)
for w in text.split():
    d[w] += 1

then you can get a list of the words, ordered by frequency of use with sorted(d, key=d.get) - the sort iterates over the dictionary keys, using the number of word occurrences as a sort key.

for w in sorted(d, key=d.get, reverse=True):
    print(w, d[w])

or, if we want a dictionary back (since Python 3.6+ preserves insertion order):

{w: d[w] for w in sorted(d, key=d.get, reverse=True)}

I am writing this detailed explanation to illustrate what people often mean by "I can easily sort a dictionary by key, but how do I sort by value" - and I think the original post was trying to address such an issue. And the solution is to do sort of list of the keys, based on the values, as shown above.

🌐
Codecademy
codecademy.com › article › how-to-sort-a-dictionary-by-key-or-value-in-python
How to Sort a Dictionary by Key or Value in Python | Codecademy
Python provides the built-in sorted() function to efficiently sort dictionaries. The sorted() function returns a new sorted list derived from the elements of any iterable. When applied to a dictionary’s items, it enables sorting by values ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
Sort a List of Dictionaries by the Value of the Specific Key in Python | note.nkmk.me
May 14, 2023 - Use the reverse argument to specify whether the sorting should be in descending or ascending order.
🌐
OneUptime
oneuptime.com › home › blog › how to sort a dictionary by value in python
How to Sort a Dictionary by Value in Python
January 25, 2026 - from operator import itemgetter scores = {'Alice': 85, 'Bob': 92, 'Charlie': 78, 'Diana': 95} # itemgetter(1) gets the second element (index 1 = value) sorted_scores = dict(sorted(scores.items(), key=itemgetter(1))) print(sorted_scores) # {'Charlie': 78, 'Alice': 85, 'Bob': 92, 'Diana': 95} # Descending sorted_scores = dict(sorted(scores.items(), key=itemgetter(1), reverse=True)) print(sorted_scores) # {'Diana': 95, 'Bob': 92, 'Alice': 85, 'Charlie': 78}
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to sort dictionary by value in python
How to Sort Dictionary by Value in Python - Spark By {Examples}
May 31, 2024 - # Below are the quick examples ... order sorted_list = sorted(my_dict.items(), key = lambda x:x[1]) # Example 2: Sort the dictionary by value in descending order sorted_list = sorted(my_dict.items(), key = lambda x:x[1], reverse = True) # Example ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › sorting-list-of-dictionaries-in-descending-order-in-python
Sorting List of Dictionaries in Descending Order in Python - GeeksforGeeks
July 23, 2025 - Explanation: sorted() sorts the list of dictionaries based on the frequency of the 'section' values, using the counter to retrieve the count for each 'section'. The reverse=True ensures the sorting is in descending order, placing more frequent ...
🌐
Miguendes
miguendes.me › how-to-sort-a-dict-in-descending-order-by-value-with-python
Python: How to Sort a Dictionary by Value in Descending Order
February 20, 2021 - The quickest way is to iterate over the key-value pairs of your current dict and call sorted passing the dictionary values and setting reversed=True. If you are using Python 3.7, regular dicts are ordered by default.
🌐
Vultr
docs.vultr.com › python › examples › sort-a-dictionary-by-value
Python Program to Sort a Dictionary by Value | Vultr Docs
November 21, 2024 - Here, adding reverse=True to the sorted() function inverts the order of sorting, resulting in the values being sorted in descending order. Create a dictionary with complex data types, such as lists, as values.