from string import *
# Recursively putting indexes of the starting point of matches into a tuple and printing them.
def countSubStringMatchExactRec(target, key, count=(), index = 0):
if target.find(key) == -1:
return count
else:
return countSubStringMatchExactRec(target[target.find(key)+len(key):],
key,
count + ((index + target.find(key)),),
index + target.find(key) + len(key))
# Iterative version:
def countSubStringMatchExactIter(target,key):
index_mover = 0
count = 0
positions = ()
while index_mover < len(target):
instance = str.find(target, key, index_mover)
if instance >= 0:
count += 1
positions = positions + (instance,)
index_mover = instance + len(key)
else:
break
return positions