Write a Python Program to Sort Words in Alphabetic Order

Python Program to Sort Words in Alphabetic Order

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Sort Words in Alphabetic Order
Python Program to Sort Words in Alphabetic Order

Write a Python Program to Sort Words in Alphabetic Order

PROGRAM: Python Program to Sort Words in Alphabetic Order

/* Python Program to Sort Words in Alphabetic Order */

# Program to sort alphabetically the words form a string provided by the user

my_str = “Hello this Is an Example With cased letters”

# To take input from the user
#my_str = input(“Enter a string: “)

# 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)

OUTPUT:

The sorted words are:
an
cased
example
hello
is
letters
this
with

 

		

Leave a Reply

Your email address will not be published. Required fields are marked *