Answer to Question #231272 in Python for bhuvana

Question #231272

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-07T15:40:57-0400


def frequency(string):
  
    
    string_list = string.split()
  
    
    uniqueWords = set(string_list)
      
    for word in uniqueWords :
        print(word , ':', string_list.count(word))
  
# Testing code
if __name__ == "__main__":
      
    sentence ='Hello world welcome to python world'
      
    
    frequency(sentence)

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