Question:
Write a program to sort the string accepted from the user
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Program to sort alphabetically the words form a string provided by the user my_str = raw_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 print("The sorted words are:") for word in words: print(word) |
Explanation:
The sort function returns the sorted data item.
Output:
1 2 3 4 5 6 |
Enter a string: GlobalSQA is the best! The sorted words are: GlobalSQA best! is the |
Leave a Reply