Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

ps3 prob 1: Somewhat close to solving the question except i can't count the instances. Instead, mine displays, albeit wrongly the index in which the match occurs. I'm still trying to figure out how to add the omitted string count into the second/subsequent numbers. But meanwhile, any ideas how to solve for count? Code as follows: def RecStrMat(target, key): ans = target.find(key) ct = 0 if ans == -1: return else: return ans, RecStrMat(target[(ans+1):],key) print(RecStrMat("atgacatgcacaagtatgcat","atgc"))

OpenStudy (anonymous):

You can a hidden argument as count to avoid it being reset, i.e.: http://codepad.org/pZOaaImC There is a catch as to how to return the count. See if you can fix it on your implementation :-)

OpenStudy (anonymous):

def RecStrMat(target, key): ans = target.find(key) if ans == -1: return 0 else: return RecStrMat(target[(ans+1):],key) +1

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!