Created
March 24, 2016 16:35
-
-
Save samwarnick/9019de3d0e622c60f65a to your computer and use it in GitHub Desktop.
a simple fuzzy search algorithm from an interview
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
fruit = ["watermelon", "apple", "oranges", "bannana"] | |
def fuzzySearch(words, term): | |
results = [] | |
if len(term) == 0: | |
return results | |
termLength = len(term) | |
for word in words: | |
wordLength = len(word) | |
if not termLength > wordLength: | |
termIndex = 0 | |
for i in range(wordLength): | |
if word[i] == term[termIndex]: | |
termIndex = termIndex + 1 | |
if termIndex == len(term): | |
results.append(word) | |
break | |
return results | |
print(fuzzySearch(fruit, "ae")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment