Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 24, 2020 03:19
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/02680982e7bb39265f59ba377f49d4b2 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/02680982e7bb39265f59ba377f49d4b2 to your computer and use it in GitHub Desktop.
#Sorting dictionary based on len function
l1={'carrot':'vegetable','red':'color','apple':'fruit'}
#Returns list of keys sorted based on len function
print (sorted(l1,key=len))
#Output:['red', 'apple', 'carrot']
#Returns list of values sorted based on len fucntion
print (sorted(l1.values(),key=len))
#Output:['fruit', 'color', 'vegetable']
#Sorting list based on len function
l1=['blue','green','red','orange']
print (sorted(l1,key=len))
#Output:['red', 'blue', 'green', 'orange']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment