Question #197618

Given a sentence S, write a program to print the frequency of each word in S, where words are sorted in alphabetical order.



Expert's answer

S = input()

words = {}
for w in S.split():
    if w in words:
        words[w] += 1
    else:
        words[w] = 1

for w in sorted(words):
    print("%s:\t%s" % (w, words[w]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS