aranthe ([personal profile] aranthe) wrote in [community profile] intro_to_cs2010-05-03 03:17 pm

PS3: Problem 1 » Solutions

I'll be posting the remaining solutions over the next few days, as soon as I have time to finish reviewing them.

PS3: Problem 1 » Solutions

# Problem 1: countSubstringMatch, countSubstringMatchRecursive
def countSubStringMatch( target, key ):
    count = 0
    while target.find( key ) > -1:
        count += 1
        target = target[target.find( key ) + len( key ):]
    return count

def countSubStringMatchRecursive( target, key ):
    if target.find( key ) < 0:
        return 0
    else:
        return 1 + countSubStringMatchRecursive( target[(target.find( key ) + len(key)):], key )