Skip to content

Instantly share code, notes, and snippets.

@samwarnick
Created March 24, 2016 16:35
Show Gist options
  • Save samwarnick/9019de3d0e622c60f65a to your computer and use it in GitHub Desktop.
Save samwarnick/9019de3d0e622c60f65a to your computer and use it in GitHub Desktop.
a simple fuzzy search algorithm from an interview
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