Exercise 95*

Write a Python function to get any string/sentence and returns the most repeated word.


def most_repeated(s):
# converting the string s to a list
L = s.split()
# initialising the most repeated words
mostRepeated = L[0]

for word in L:
if L.count(word) > L.count(mostRepeated):
mostRepeated = word
return mostRepeated

# testing the algorithm
s = "Python is object oriented programming language. Python is also also used for data sciences. Python is open source"
print(most_repeated(s)) # the out put is: Python

Younes Derfoufi

Leave a Reply