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