Friday 7 October 2022

Split the sentence into words

my_str = "Welcome to Python"

# breakdown the string into a list of words

words = my_str.split()

# sort the list

words.sort()

# display the sorted words

print("The sorted words are:")

for word in words:

   print(word)


Output:

Sorted words are:
Python
Welcome
to

No comments:

Post a Comment