Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
more descriptiveness by taking out a random i variable
  • Loading branch information
jabagawee committed Oct 3, 2012
1 parent a2d655d commit b39e2a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions algorithms/searching/kmp_search.py
Expand Up @@ -28,13 +28,13 @@ def search(string, word):
if word_length > string_length:
return offsets
q = 0 # q is the number of characters matched
for i in xrange(string_length):
while q > 0 and word[q] != string[i]:
for index, letter in enumerate(string):
while q > 0 and word[q] != letter:
q = prefix[q - 1] # next character does not match
if word[q] == string[i]:
if word[q] == letter:
q += 1
if q == word_length:
offsets.append(i - word_length + 1)
offsets.append(index - word_length + 1)
q = prefix[q - 1] # look for next match
return offsets

Expand Down

0 comments on commit b39e2a6

Please sign in to comment.