Answers for "python program to print repeated words in a string"

0

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)
Posted by: Guest on July-01-2021
0

count repeated characters in a string python

# Python 3+
import collections
collections.Counter(input_string)

# Python 2 or custom results.
{key: string.count(key) for key in set(string)}

# Other ways are too slow. In the source, You can see the proves.
Posted by: Guest on June-12-2021
0

repetition of word in python

#repeatition of the object n times
n=int(input('enter the number to be repeated='))
print('hello '*n)

#output:
enter the number to be repeated=
hello .. .....
Posted by: Guest on November-28-2021

Code answers related to "python program to print repeated words in a string"

Python Answers by Framework

Browse Popular Code Answers by Language