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.
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])))
Comments
Leave a comment