Created
November 11, 2015 21:22
-
-
Save oleksmarkh/1c76f96d30fc142f09a4 to your computer and use it in GitHub Desktop.
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
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