Skip to content

How to find most repeated word in a string in Python?

from collections import Counter

# Example phrase 
phrase = "John is the son of John second. Second son of John second is William second."
split_phrase = phrase.split()

# create counter object
Counter = Counter(split_phrase)

most_occured_words = Counter.most_common(4)
  
print(most_occured_words)
See also  How to subscribe using mqtt in PHP?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.