Python Program to sort alphabetically the words form a string provided by the user

Python Program to sort alphabetically the words form a string provided by the user

my_str = input("Enter a string: ")  

# breakdown the string into a list of words  

words = my_str.split()  

# sort the list  

words.sort()  

# display the sorted words  

for word in words:  

   print(word)  

 

Output:

Enter a string: Welcome to the codingpython.You can find latest python programs here.
Welcome
can
codingpython.You
find
here.
latest
programs
python
the
to
>>>

 

Screenshot:

 

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *