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
๐ŸŒ
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 - To sort a list of dictionaries according to the value of the specific key, specify the key argument of the sort() method or the sorted() function. By specifying a function to be applied to each element of the list, it is sorted according to the result of that function. See the following article for more information. How to use the key argument in Python ...
Discussions

How to sort a list containing dictionary items?
List objects have a sort function to sort the list in-place. This function has a key parameter to specify a function that will be called on each item in the list, after which the items will be sorted based on the results of that function. It also accepts a reverse parameter that, if set to True, will cause sort to sort the list in descending order. Let's say you have a list students that contains Student objects. To sort the students by age from oldest to youngest, you'd do students.sort(key = lambda x: x.Age, reverse=True). Sorting your list of dictionaries is done in pretty much the same way. See this if you need more examples. Keep in mind that in your list, the currency values are strings, not integers. You'll need to convert them first, otherwise they won't be sorted correctly. You can do that in the lambda function you pass to sort. Incidentally, using variable names like list is bad practice. You're overriding the built-in list class by doing that. More on reddit.com
๐ŸŒ r/learnpython
4
2
September 30, 2023
Sort a list of dictionaries by keys in Python - Stack Overflow
I know this can be done by getting key as list then sort them and then create another list, but i am looking for more elegant may be a one liner solution ... You aren't just sorting the dicts, but you are altering their content with some unspecified logics. ... Why are you making dictionaries that ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Sort list of dictionaries by key - Stack Overflow
I have a list of dictionaries where the order of the keys is not consistent. Ideally I would like 'vid' to always come first with 'name' being second. As you can see below, sometimes 'name' comes f... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Sorting dict keys and a dict inside a dict
Dictionaries are not sortable. They preserve insertion order only. If you need sorted data, use a different data structure. More on reddit.com
๐ŸŒ r/learnpython
30
47
July 4, 2022
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ sort-list-of-dictionaries-python-by-multiple-keys
Sort List of Dictionaries by Multiple Keys - Python - GeeksforGeeks
July 23, 2025 - Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-sort-python-dictionaries-by-key-or-value
Sort Python Dictionary by Key or Value - Python - GeeksforGeeks
Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Published ย  January 13, 2026
๐ŸŒ
Medium
medium.com โ€บ @vipinc.007 โ€บ python-sort-a-list-of-dictionaries-by-key-d9347f592b2f
Python | sort a list of dictionaries by key | by Vipin Cheriyanveetil | Medium
February 21, 2023 - Python | sort a list of dictionaries by key just sort it Sorting a list of dictionaries by a key is a common operation in Python, especially when working with data from APIs or databases โ€ฆ
๐ŸŒ
Medium
medium.com โ€บ @python-javascript-php-html-css โ€บ sorting-a-list-of-dictionaries-in-python-by-a-specific-key-0e93fa7ffff1
Using a Specific Key to Sort a List of Dictionaries in Python | by Denis Bรฉlanger ๐Ÿ’Žโšกโœจ | Medium
August 24, 2024 - The first script uses the sorted() function in combination with a lambda function to sort a list of dictionaries. The sorted() function is a built-in Python function that returns a new sorted list from the items in an iterable. By using a lambda function as the key parameter, we can specify ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-sort-dictionary-by-key
Python Sort Dictionary by Key โ€“ How to Sort a Dict with Keys
May 25, 2023 - In this article, we will explore how to sort a dictionary with keys in Python. We will break down the steps for easy follow up and understanding. I recommend that you be familiar with the Python programming language to get the most out of this article. In Python, dictionaries are a powerful ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-sort-dictionaries-list-by-keys-value-list-index
Python - Sort dictionaries list by Key's Value list index - GeeksforGeeks
April 5, 2023 - This is done using a lambda function that accesses the K key and the idx index of the corresponding list for each dictionary. Store the sorted result in a variable called res. Print the result using the print() function and passing the string representation of res. Below is the implementation of the above approach: ... # Python3 code to demonstrate working of # Sort dictionaries list by ...
๐ŸŒ
Real Python
realpython.com โ€บ sort-python-dictionary
Sorting a Python Dictionary: Values, Keys, and More โ€“ Real Python
December 14, 2024 - More examples and explanations of the key parameter will come later in the tutorial when you use it to sort dictionaries by values or nested elements. If you take another look at the results of this last sorting, you may notice the stability of the sorted() function. The three elements, aa, ba and ca, are equivalent when sorted by their second character. Because theyโ€™re equal, the sorted() function conserves their original order. Python guarantees this stability. Note: Every list ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to sort a list containing dictionary items?
r/learnpython on Reddit: How to sort a list containing dictionary items?
September 30, 2023 -

Let's say i have a list from a json like this:

list = [
{
    "name": "Player1",
    "currency": "10"
},
{
    "name": "Player2",
    "currency": "15"
},
    {
    "name": "Player3",
    "currency": "7"
}

]

How do i sort it based on the amount of currency a player has so that i can get the richest players using simple list indexes? For example if i want the details of the second richest player, i sort the list based on the amount of currency player has and then do a simple list[1] to get their details. How do i achieve this?

Top answer
1 of 4
5
List objects have a sort function to sort the list in-place. This function has a key parameter to specify a function that will be called on each item in the list, after which the items will be sorted based on the results of that function. It also accepts a reverse parameter that, if set to True, will cause sort to sort the list in descending order. Let's say you have a list students that contains Student objects. To sort the students by age from oldest to youngest, you'd do students.sort(key = lambda x: x.Age, reverse=True). Sorting your list of dictionaries is done in pretty much the same way. See this if you need more examples. Keep in mind that in your list, the currency values are strings, not integers. You'll need to convert them first, otherwise they won't be sorted correctly. You can do that in the lambda function you pass to sort. Incidentally, using variable names like list is bad practice. You're overriding the built-in list class by doing that.
2 of 4
2
list_ = [ { "name": "Player1", "currency": "10" }, { "name": "Player2", "currency": "15" }, { "name": "Player3", "currency": "7" } ] new_list_ = sorted(list_, key=lambda x: int(x["currency"])) print(new_list_) NB. Strongly recommend against using Python types/names for variable names, as it makes it harder to access original features. Hence, appended _ to list from your example. new_list_[-2] will reference the second-richest player (well, not if they have matching currency levels. If you want that, you will need to collect the unique values, find the second highest, and then find the players with that amount. Note, sorted can use the reversed keyword. PS. Example to find second richest, amounts = sorted(set(int(x['currency']) for x in new_list_)) if len(amounts) > 1: second_highest = amounts[-2] print(f"{second_highest=}") for player in new_list_: if int(player['currency']) == second_highest: print(player["name"]) else: print("No player is second richest") NB. Might be easier to convert the currency values to numbers before doing anything else.
๐ŸŒ
CodeConverter
codeconverter.com โ€บ articles โ€บ python-sort-list-of-dictionaries
Python: Sort a List of Dictionaries by Key Value | CodeConverter Blog
February 12, 2026 - Sort lists of dicts in Python using sorted(), key functions, and multiple criteria. Handle real-world data sorting.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-sort-a-list-of-dictionaries-by-a-key-in-python-398246
How to sort a list of dictionaries by a key in Python | LabEx
Learn how to efficiently sort a list of dictionaries by a specific key in Python. Discover various sorting techniques and their use cases to enhance your Python programming skills.
๐ŸŒ
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 - In Python, you can use the sorted() function to sort a list of dictionaries by a specific value of the dictionary. The sorted() function takes two arguments: the list to be sorted, and a key function that maps each element of the list to a value that is used for sorting.
๐ŸŒ
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
Imagine a registration form that ... the key-value pair in the python dictionary. But why is there a need to solve the data stored in it? Sorting a dictionary is useful when there is a need to organize data for better readability, efficient reporting, or accurate analysis. While dictionaries are optimized for quick access, their order is not always meaningful. Some benefits of sorting are listed as ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python sort dictionary by key
Python Sort Dictionary by Key - Spark By {Examples}
May 31, 2024 - We can sort the dictionary by key using a sorted() function in Python. It can be used to sort dictionaries by key in ascending order or
๐ŸŒ
Temp Mail
tempmail.us.com โ€บ temp mail โ€บ blog โ€บ python โ€บ using a specific key to sort a list of dictionaries in python
Using a Specific Key to Sort a List of Dictionaries in Python
July 24, 2024 - Sorting a list of dictionaries based on a specific key's value is a typical Python programming task. This approach is very effective when working with data sets that need to be organized for easier reading or analysis. In this post, we will look at how to sort a list of dictionaries in Python by ...
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ dictionary โ€บ sort dictionary list using a tuple key
Sort Python dictionary list using a tuple key - 30 seconds of code
January 4, 2023 - Sorting a list of dictionaries in Python can seem intimidating at first. This is especially true if you want to sort using multiple keys. Luckily, the sorted() function can be used to sort a list of dictionaries using a tuple key. Simply return a tuple with the order of keys you want to sort by and ...
๐ŸŒ
YoungWonks
youngwonks.com โ€บ blog โ€บ python-sort-dictionary-by-key-or-value
Python Sort Dictionary by Key or Value
April 10, 2023 - The sorted function returns a list of tuples containing the keys and values of the dictionary. We can create a new dictionary and store the keys and values using a for-loop. This gives us a dictionary sorted by values. Here is another way to sort the dictionary based on values. The zip function can also be used to sort dictionaries using values. To learn more about dictionaries, read our other blog: https://www.youngwonks.com/blog/Python...