My if statement looks weird, but I can't think of how I prevent of -1 value from printing :
### script counts the number of times that a key string appears in target string
from string import *
def countSubStringMatch(target,key):
value = target.find(key, 0)
print value
while value > -1:
value = value + 1
value = target.find(key, value)
if value != -1:
print value
else:
break
countSubStringMatch("atgacatgcacaagtatgcat","atg")
This is my output:
0
5
15