Question #217568

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.

Expert's answer

sentence = input('Enter your sentence here: ')
sentence1 = sentence.split(' ')
set1 = [i for i in sentence1]
list1 = []
for i in set1:
    ex = False
    for x in list1:
        if x == i :
            ex = True
            break
    if not ex :
        list1.append(i)
for i in list1:

    print(i, ':', set1.count(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!

LATEST TUTORIALS
APPROVED BY CLIENTS