This is a python program to sort words in alphabetic order. (This program will only run on python 3.x versions)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Program to sort alphabetically the words # form a string provided by the user # 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 for word in words: print (word) |
Output:
Enter a string: This is a python program to sort words in alphabetical order
This
a
alphabetical
in
is
order
program
python
sort
to
words
Comments
Post a Comment