Created
September 24, 2021 05:56
-
-
Save SaraM92/c221e555995a9527425701b3b476e1af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dicts_lists = [ | |
{ | |
"Name": "James", | |
"Age": 20, | |
}, | |
{ | |
"Name": "May", | |
"Age": 14, | |
}, | |
{ | |
"Name": "Katy", | |
"Age": 23, | |
} | |
] | |
#There are different ways to sort that list | |
#1- Using the sort/ sorted function based on the age | |
dicts_lists.sort(key=lambda item: item.get("Age")) | |
#2- Using itemgetter module based on name | |
from operator import itemgetter | |
f = itemgetter('Name') | |
dicts_lists.sort(key=f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment