-
-
Save IndhumathyChelliah/02680982e7bb39265f59ba377f49d4b2 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
#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