Sort set of words in ascending order in Python

Source code :

my_str = "Hello this Is an Example With cased letters"
words = my_str.split()
words.sort()
print("The sorted words are:")
for word in words:
   print(word)

Output :

The sorted words are:
Example
Hello
Is
With
an
cased
letters
this

Algorithm :

  1. Declare the set of words
  2. Use split() function for break the sentence
  3. Use sort() function for sorting the elements
  4. Finally print the result

Output :


                

Comments :