Answer to Question #217520 in Python for Bhargav

Question #217520
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-07-16T03:18:01-0400
S = str(input("Enter a sentence: \n"))  
str = S.split()
tempS=[]
for i in str:        
	if i not in tempS: 
		tempS.append(i)
  
print("Input Sentence:\n" + S)
print("\nWord        Frequency")
for i in range(0, len(tempS)):
	print("%9s:%5s"%(tempS[i].ljust(20),str.count(tempS[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