Q. Write a Python program to find the second most repeated word in a given string.
Answer =
string = input("Enter a string :-") lst = string.split() max = 0 sec = 0 for i in lst: if lst.count(i) >= max : max = lst.count(i) elif lst.count(i) >= sec : sec = lst.count(i) secmaxvalue = i print("Second most repeated word :-", secmaxvalue )
Output :-
Enter a string :-This is Pathwalla website This provide you solution of sumita arora class 11 , 12 This is our pleasure.
Second most repeated word :- is
>>>
Here "This" repeated 3 times and "is" repeated 2 times.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )