Write a python script to take input of string and find maximum occurrence words in inputted string. - Pratik Ghelani

Pratik Ghelani

Breaking

Sunday, May 10, 2020

Write a python script to take input of string and find maximum occurrence words in inputted string.

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