my question here
Q4. Ask the user for a sentence and print out a table of words in that sentence. The words should be printed alphabetically with its number of occurrences next to it.
Note: You should avoid editing the list in a for loop traverses over. If you need to edit a list use the while loop.
Q4. Ask the user for a sentence and print out a table of words in that sentence. The words should be printed alphabetically with its number of occurrences next to it.
Note: You should avoid editing the list in a for loop traverses over. If you need to edit a list use the while loop.
#Q4 s = input("Enter a sentence: ") previous = "" L = s.split() L.sort() for w in L: current = w if current == previous: continue else: c = L.count(w) print(w,c) previous = current