Ways to sort list of dictionaries by values in Python - Using lambda function Last Updated : 07 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will cover how to sort a dictionary by value in Python. Sorting has always been a useful utility in day-to-day programming. Dictionary in Python is widely used in many applications ranging from competitive domain to developer domain(e.g. handling JSON data). Having the knowledge to sort dictionaries according to their values can prove useful in such cases. There are 2 ways to achieve this sorting: What is the lambda function in python? This article deals with sorting using the lambda function and using the "sorted()" inbuilt function. Various variations can also be achieved for sorting the dictionaries. For descending order : Use "reverse = True" in addition to the sorted() function.For sorting w.r.t multiple values: Separate by "comma" mentioning the correct order in which sorting has to be performed. Example: Python3 # Python code demonstrate the working of # sorted() with lambda # Initializing list of dictionaries list = [{"name": "Nandini", "age": 20}, {"name": "Manjeet", "age": 20}, {"name": "Nikhil", "age": 19}] # using sorted and lambda to print list sorted # by age print("The list printed sorting by age: ") print(sorted(list, key=lambda i: i['age'])) print("\r") # using sorted and lambda to print list sorted # by both age and name. Notice that "Manjeet" # now comes before "Nandini" print("The list printed sorting by age and name: ") print(sorted(list, key=lambda i: (i['age'], i['name']))) print("\r") # using sorted and lambda to print list sorted # by age in descending order print("The list printed sorting by age in descending order: ") print(sorted(list, key=lambda i: i['age'], reverse=True)) Output: The list printed sorting by age: [{'age': 19, 'name': 'Nikhil'}, {'age': 20, 'name': 'Nandini'}, {'age': 20, 'name': 'Manjeet'}] The list printed sorting by age and name: [{'age': 19, 'name': 'Nikhil'}, {'age': 20, 'name': 'Manjeet'}, {'age': 20, 'name': 'Nandini'}] The list printed sorting by age in descending order: [{'age': 20, 'name': 'Nandini'}, {'age': 20, 'name': 'Manjeet'}, {'age': 19, 'name': 'Nikhil'}] Next Article -> Ways to sort list of dictionaries by values in Python - Using itemgetter Comment More infoAdvertise with us Next Article Ways to sort list of dictionaries by values in Python â Using itemgetter M manjeet_04 Follow Improve Article Tags : Python python-dict python-lambda Python dictionary-programs Practice Tags : pythonpython-dict Similar Reads Ways to sort list of dictionaries by values in Python â Using itemgetter In this article, we will cover how to sort a dictionary by value in Python. To sort a list of dictionaries by the value of the specific key in Python we will use the following method in this article.In everyday programming, sorting has always been a helpful tool. Python's dictionary is frequently ut 2 min read Sort Python Dictionary by Key or Value - Python There are two elements in a Python dictionary-keys and values. You can sort the dictionary by keys, values, or both. In this article, we will discuss the methods of sorting dictionaries by key or value using Python.Sorting Dictionary By Key Using sort()In this example, we will sort the dictionary by 6 min read Python | Sort the list alphabetically in a dictionary In Python Dictionary is quite a useful data structure, which is usually used to hash a particular key with value, so that they can be retrieved efficiently. Let's see how to sort the list alphabetically in a dictionary. Sort a List Alphabetically in PythonIn Python, Sorting a List Alphabetically is 3 min read Sort a list of strings in lexicographical order in Python We are given a list of strings and our task is to sort them in lexicographical order, which means alphabetical order either from A to Z (ascending) or Z to A (descending). This is a common operation when organizing or comparing strings in Python. For example:Input: ["banana", "apple", "cherry", "dat 2 min read How to Sort a Set of Values in Python? Sorting means arranging the set of values in either an increasing or decreasing manner. There are various methods to sort values in Python. We can store a set or group of values using various data structures such as list, tuples, dictionaries which depends on the data we are storing. We can sort val 7 min read Python - Sort list of list by specified index When working with a list of lists, we often need to sort the inner lists based on the values at a specific index. Sorting by a specified index is useful in the custom ordering of multidimensional data. In this article, we will explore different ways to sort a list of lists by a specified index in Py 3 min read Like