Input:- sentence = input("Enter the string:") def word_count(str): counts = dict() words = str.split() for word in words: if word in counts: counts[word] += 1 else: counts[word] = 1 return counts print( word_count(sentence)) Output:-
No comments:
Post a Comment