Python Program to Sort Words in Alphabetical Order

In this example, we will write a program to take a string input from the user and sort the words in that given string in alphabetical order. To better understand this example, make sure you have knowledge of the following tutorials:-

Python Program to Sort Words in Alphabetical Order

The output of the above program is:-

Enter a string: My Name is John Doe
The sorted words are:
Doe
John
My
Name
is
Program Explanation:
The sorting of string into alphabetical order is quite straightforward. The input string is taken from user and broken down into words using the split() method of string. Sort() method sorts the words in alphabetical order which is then displayed using a for a loop.
SHARE Python Program to Sort Words in Alphabetical Order

You may also like...

Leave a Reply

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

Share