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-09-08T16:10:41-0400
print("Word Frequency:")
S = str(input("Enter a sentence: \n"))
str = S.split()
tempS=[]
for i instr:
if i notin tempS:
tempS.append(i)
print("Input Sentence:\n" + S)
print("\nWord Frequency")
for i inrange(0, len(tempS)):
print("%9s:%5s"%(tempS[i].ljust(20),str.count(tempS[i])))
Comments