Skip to content

Instantly share code, notes, and snippets.

@skaasten
Created April 27, 2020 19:16
Show Gist options
  • Save skaasten/6886912f3649e54bf76e7931d469c815 to your computer and use it in GitHub Desktop.
Save skaasten/6886912f3649e54bf76e7931d469c815 to your computer and use it in GitHub Desktop.
exact_match
def exact_match(text, query):
i = 0
j = 0
matches = 0
while True:
if text[i] == query[j]:
i+=1
j+=1
matches += 1
else:
j=0
if matches == 0:
i+=1
matches = 0
if j == len(query):
return True
elif i == len(text):
return False
print exact_match("hello world", "lo w")
print exact_match("hello world", "world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment