Skip to content

Instantly share code, notes, and snippets.

@oleksmarkh
Created November 11, 2015 21:22
Show Gist options
  • Save oleksmarkh/1c76f96d30fc142f09a4 to your computer and use it in GitHub Desktop.
Save oleksmarkh/1c76f96d30fc142f09a4 to your computer and use it in GitHub Desktop.
def indexof(fromstr, substr):
f = s = 0
while f < len(fromstr):
if fromstr[f] == substr[s]:
if s == len(substr) - 1:
return f - s
s += 1
else:
s = 0
f += 1
return -1
assert indexof('something', 'else') == -1
assert indexof('something', 's') == 0
assert indexof('something', 'g') == 8
assert indexof('something', 'some') == 0
assert indexof('something', 'thing') == 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment