Answer to Question #231275 in Python for bhuvana

Question #231275

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-09-09T17:08:32-0400
words = {}
for ​str in input().split():
    word = ("".join([ c if c.isalnum() else "" for c in str ]))
    if word not in words:
        words[word] = 1
    else:
        words[word] += 1

for ​word in sorted(words):
    print(word, ": ", words[word], sep='

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