In this HackerRank Find a string problem you have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.

HackerRank Find a string in python problem solution

HackerRank Find a string in python problem solution

import re
n = raw_input().strip()
m = raw_input().strip()
count = 0
for i in range(len(n)-len(m)+1):
    if n[i:i+len(m)] == m:
        count += 1
print count
#m = '?=('+m+')'
#print len(re.findall(m, n))

Second solution

a = input()
b = input()

def KMP(string, sub):
    count = 0
    sub = list(sub)
    s = [1] * (len(sub) + 1)
    shift = 1
    for i in range(len(sub)):
        while shift <= i and sub[i] != sub[i-shift]:
            shift += s[i-shift]
        s[i+1] = shift
 
    start = 0
    matchLen = 0
    for c in string:
        while matchLen == len(sub) or matchLen >= 0 and sub[matchLen] != c:
            start += s[matchLen]
            matchLen -= s[matchLen]
        matchLen += 1
        if matchLen == len(sub):
            count = count+1
    print(count)

KMP(a,b)