Answer to Question #228552 in Python for Varma

Question #228552

Given a sentence S, write a program to print the frequency of each word in S. The output order should correspond with the word's input order of appearance.

Input


The input will be a single line containing a sentence S.

Output


The output contains multiple lines, with each line containing a word and its count separated by ": " with the order of appearance in the given sentence.


1
Expert's answer
2021-08-23T01:17:58-0400
s = str(input())  
s2 = s.split()
temp_s=[]
for i in s2:              
    if i not in temp_s: 
       temp_s.append(i)  




print("Word                  Frequency")
for i in range(0, len(temp_s)): 
    print("%10s:%5s"%(temp_s[i].ljust(20),s2.count(temp_s[i])))   

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
APPROVED BY CLIENTS