In: Computer Science
Create a Python program that:
The program should:
Save the program as a Python module, and submit the program through this assignment.
The following program is according to what was asked. Wasn't really sure in what order the elements of the list are to be sorted. So, I've sorted according to word length. Also there is a commented out sort statement incase the sorting should be in reverse order or just using the sort function. Please use accordingly. Each and every step is explained in the solution for easier understanding.
string = input("Enter a sentence or phrase of your choice\n") # accepting user input
lists = list(string.split()) # splitting the words in the string and storing individual words in a list
lists.sort(key=len) # sorting the list of words in the order os ascending word length
# lists.sort(reverse=True)
# lists.sort()
print(*lists, sep="\n") # unpacking the list to get elements and printing in separate lines
print("\nAll elements in the list have been printed") # displaying message after all the elements have been printed
OUTPUT: