Created
August 23, 2020 17:46
-
-
Save robgon-art/8d7f08909e0ae837de2cb843c0245102 to your computer and use it in GitHub Desktop.
Check for repeated phrases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to check if the text contain a repeated phrase | |
def repeats(s, num): | |
substrings = {} | |
parts = s.split(' ') | |
does_repeat = False | |
for i in range(len(parts)-num): | |
substring = parts[i] | |
for j in range(1, num): | |
substring += ' ' + parts[i+j] | |
if substring in substrings: | |
return True | |
else: | |
substrings[substring] = True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment