Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to sort dictionary in python by lambda

dict = [
    {"name": "Fuad", "age": 22},
    {"name": "Bristy", "age": 20},
    {"name": "Tonni", "age": 17},
    {"name": "Riya", "age": 15},
    {"name": "Badol", "age": 19},
]

print("Result after sort - ")
res = sorted(dict, key=lambda x: x['age'], reverse=True)
print(res)
Comment

how to sort dictionary in ascending order by sorted lambda function in python

dict = [
    {"name": "Fuad", "age": 22},
    {"name": "Bristy", "age": 20},
    {"name": "Tonni", "age": 17},
    {"name": "Riya", "age": 15},
    {"name": "Badol", "age": 19},
]

print("Result after sort - ")
print(sorted(dict, key=lambda x: x['age']))
print("
")
Comment

PREVIOUS NEXT
Code Example
Python :: python check if included in list 
Python :: merge dataframe using pandas 
Python :: how to test value error in pytest in python 
Python :: 2d array row and column index 
Python :: dictionary comprehension python 
Python :: 1d array operations in python 
Python :: Python recursively find files with specific ext 
Python :: python = align 
Python :: python tkinter button color 
Python :: how to speed up python code 
Python :: Split the string using the separator 
Python :: pytorch convert tensor dtype 
Python :: python online practice test 
Python :: python googledriver download 
Python :: objects.filter django 
Python :: curl to python 
Python :: how to access a dictionary within a dictionary in python 
Python :: Math Module log10() Function in python 
Python :: boolien in python 
Python :: python is scripting language or programming language 
Python :: dockerize django app 
Python :: merge sort of two list in python 
Python :: python open aspx file 
Python :: ValueError: Please provide a TPU Name to connect to. site:stackoverflow.com 
Python :: dataframe to csv 
Python :: Making a delete request using python 
Python :: alexa python get slot value 
Python :: python change version 
Python :: CMake Error at pybind11/tools/FindPythonLibsNew.cmake:131 (message): Python config failure: 
Python :: scikit learn decision tree 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =