Last active
December 12, 2015 02:34
-
-
Save AjayAjaal/22fd62b3f1b8e11ec106 to your computer and use it in GitHub Desktop.
Pattern Matching Algorithms
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
def naive(pattern, text): | |
occurrences = [] | |
for i in range(len(text) - len(pattern) + 1): | |
match = True | |
for k in range(len(pattern)): | |
if text[i+k] != pattern[k]: | |
match = False | |
break | |
if match: | |
occurrences.append(i) | |
return occurrences | |
print naive('word', 'There would have been a time for such a word') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment