Sorting words of a string Alphabetically
A simple code to sort the words of a statement in Alphabetical order
Welcome to the code! We will be taking a statement from the user and using the code below, we can sort the words of that statement in alphabetical order. To understand this program well, it’s suggested to know the following concepts well; “For loop in Python, Strings in Python, and Method Strings”.
Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!
string = input("Enter the statement you want to sort: ") # breakdown the string into a list of words words = [word.lower() for word in my_str.split()] # sort the list words.sort() # display the sorted words print("The sorted words are:") for word in words: print(word)