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 :: pipilika search engine 
Python :: all the positions of a letter occurrences in a string python 
Python :: python trie 
Python :: read a file and split the words python 
Python :: write text in list to text file python 
Python :: python match phone number 
Python :: python download for ubuntu 20.04 
Python :: declare numpy zeros matrix python 
Python :: django rest framework 
Python :: promote a row in panda dataframe to header 
Python :: double for in python 
Python :: How to find xpath by contained text 
Python :: python how to get current line number 
Python :: clearing canvas tkinter 
Python :: python how to use input 
Python :: python selenium set attribute of element 
Python :: how to save a neural network pytorch 
Python :: rename key in python dictionary 
Python :: seaborn correlation 
Python :: channel lock command in discord.py 
Python :: delete the content from the entry form in tkinter python 
Python :: port 5432 failed: timeout expired 
Python :: upload py file using flask 
Python :: how to draw a rectangle in pygame 
Python :: add custom field to serializer 
Python :: python set intersection 
Python :: pandas reset index without adding column 
Python :: search google images python 
Python :: how to import date python 
Python :: sleep in python 3 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =