-
-
Save IndhumathyChelliah/5d692001b83e991fa4c2bed65b5387d7 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
s1="Hello How are you" | |
#Splits the string and sort based on ascii values. | |
print (sorted(s1.split())) | |
#Output:['Hello', 'How', 'are', 'you'] | |
#Splits the string and sort it after performing str.lower on all items | |
print (sorted(s1.split(),key=str.lower)) | |
#Output:['are', 'Hello', 'How', 'you'] | |
d1={'apple':1,'Banana':2,'Pears':3} | |
#Returns list of keys ,sorted based on ascii values | |
print (sorted(d1)) | |
#Output:['Banana', 'Pears', 'apple'] | |
#Returns list of keys,sorted after peforming str.lower on all items | |
print (sorted(d1,key=str.lower)) | |
#Output:['apple', 'Banana', 'Pears'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment