Answer to Question #197618 in Python for Vinay

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.



1
Expert's answer
2021-05-23T14:39:21-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS