Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 24, 2020 03:34
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/5d692001b83e991fa4c2bed65b5387d7 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/5d692001b83e991fa4c2bed65b5387d7 to your computer and use it in GitHub Desktop.
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