Program to sort the words in Alphabetic order in Python. The program contains input of a sentence, splitting sentence in words by inbuilt function, sorting the list and display by inbuilt functions. This program is for class 11,12, beginners and B Tech computer science students.
Program to sort the words in Alphabetic order
What will this program do ?
This program will take a sentence string as input. Then in output it will arrange the input words in Alphabetic order.
Source Code :
i=0
my_str = input("Enter a string: ")
words = my_str.split()
words.sort()
#print(i)
for word in words:
print(word)
Source code Explanation :
Step 1: Enter the strings
my_str = input(“Enter a string: “)
Step 2: breakdown the string into a list of words
words = my_str.split()
Step 3: sort the list
words.sort()
step 4: display the sorted words
for word in words:
print(word)
Output :
RESTART: C:/csstudy/source code file 2/Python Program to Sort Words in Alphabetic Order.py Enter a string: india is a beautiful country i am pleeased to be its citizens a am be beautiful citizens country i india is its pleeased to >>>
Output Explanation:
Program to give output start from IDLE
RESTART: C:/csstudy/source code file 2/Python Program to Sort Words in Alphabetic Order.py
Step 1: String is entered
Enter a string: india is a beautiful country i am pleeased to be its citizens
step2: they are arranged in alphabetic order and printed
a
am
be
beautiful
citizens
country
i
india
is
its
pleeased
to
Conclusion :
The program is working fine.
Thank you for reading , learning and copying the source code of Program to sort the words in Alphabetic order in Python. The program contains input of a sentence, splitting in word by inbuilt function, sorting the list and display by inbuilt function. This program is for class 11,12, beginners and B Tech computer science students. Below are the links provided for more program like this one , class 11,12 practical file and python projects:
/category/python-programs/
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study