Answer to Question #247258 in Python for Raju

Question #247258

Word Count

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.


1
Expert's answer
2021-10-05T21:26:57-0400
InputString = str(input("Enter a string: "))  
str = InputString.split()
tempStr=[]
for i in str:              
    if i not in tempStr: 
       tempStr.append(i)  

print("Word                  Frequency")
for i in range(0, len(tempStr)): 
    print("%10s:%5s"%(tempStr[i].ljust(20),str.count(tempStr[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
New on Blog
APPROVED BY CLIENTS