In this program, we will take a string as input and find the second most repeated word in a given string.
Steps to solve the program
- Take a string as input and create an empty dictionary.
- Use for loop to iterate over each word of the string.
- Add a word as the key and its occurrences in a string as the value in the dictionary.
- Use sorted() and lambda function to sort the dictionary by values.
- Print the second most repeated word in a string.
Output :