In this python program, we will learn how to sort words in alphabetical order from a string provided by the user. In this program, we will use
split() function to break the strings into a list of words and use
sort() function to sort the list of the words in alphabetical order.
Here is the source code of the program to sort the words in alphabetical order from a string provided by the user.
# Python Program to Sort Words in Alphabetic Order from a String Provided by the User # To take input from 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 print("The sorted words are:") for word in words: print(word)
Enter a string: tutorialsrack is an online learning website
The sorted words are: