Prerequisite : Dictionary data structure
Given a string, Find the 1st repeated word in a string.
Input : "Ravi had been saying that he had been there" Output : had Input : "Ravi had been saying that" Output : No Repetition Input : "he had had he" Output : he
- First split given string separated by space.
- Now convert list of words into dictionary using collections.Counter(iterator) method. Dictionary contains words as key and it’s frequency as value.
- Now traverse list of words again and check which first word has frequency greater than 1.
- Second most repeated word in a sequence in Python
- Find frequency of each word in a string in Python
- Python Dictionary to find mirror characters in a string
- Python | Count occurrences of each word in given text file (Using dictionary)
- Python | Convert string dictionary to dictionary
- Python - Get Nth word in given String
- Python - Kth word replace in String
- Python | Replace rear word in String
- Python | Removing Initial word from string
- Python | Converting list string to dictionary
- Python program to create a dictionary from a string
- Python | Converting String content to dictionary
- Python | Convert dictionary object into string
- Python - Concatenate Dictionary string values
- Python program to capitalize the first and last character of each word in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.