def strStr(haystack, needle): if not needle: return 0 for index, value in enumerate(haystack): if value==needle[0] and haystack[index:len(needle)+index]==needle: return index return -1 print strStr("hello", "ll") print strStr("aaaaa", "bba")
result
G:\>python 28.py 2 -1 G:\>