Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
 
PREVIOUS NEXT
Tagged: #sort #dictionary #python #lambda
ADD COMMENT
Topic
Name
8+5 =