Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Created September 24, 2021 05:56
Show Gist options
  • Save SaraM92/c221e555995a9527425701b3b476e1af to your computer and use it in GitHub Desktop.
Save SaraM92/c221e555995a9527425701b3b476e1af to your computer and use it in GitHub Desktop.
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