Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 24, 2020 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/d9b3cbaf3a67ab90afa438ba97ac9c8a to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/d9b3cbaf3a67ab90afa438ba97ac9c8a to your computer and use it in GitHub Desktop.
from operator import itemgetter
#Creating list of dictionaries
d1=[{'name':'indhu','age':30},
{'name':'karthi','age':7},
{'name':'sarvesh','age':3}]
#Sorted based on key(age) in the dictionary
print (sorted(d1,key=itemgetter('age')))
#Output:[{'name': 'sarvesh', 'age': 3}, {'name': 'karthi', 'age': 7}, {'name': 'indhu', 'age': 30}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment