Answer to Question #217568 in Python for Bhargav

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.
1
Expert's answer
2021-07-17T10:42:25-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS