def simplefind(text, pat): n = len(text) m = len(pat) for i in range(n-m): j = 0 while 1: print text[i+j], if text[i+j] != pat[j]: break j = j + 1 if j == m: return i print return -1 text = "This is a text to search." pat = "ear" print simplefind(text, pat)