Python Program to Sort Words in Alphabetic Order
Simple python example code:- The split() method splits the string at whitespaces.
my_str = "Hello world, Python tutorial" words = my_str.split() words.sort() for word in words: print(word)
Input string is taken from user
input_str = input("Enter a string: ") # breakdown the string into a list of words words = input_str.split() # sort the list words.sort() print("The sorted words are:") for word in words: print(word)
Do comment if you have any doubts and suggestions on this Python code.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.