PS3: Problem 4 » Solution
May. 7th, 2010 10:26 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png) aranthe posting in
aranthe posting in ![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png) intro_to_cs
intro_to_csOops! I almost forgot about problem 4. I didn't have time to attempt a recursive solution for this one. (Off the top of my head, I think the key would be to encapsulate the loop portion into a recursive function, rather than to make the entire subStringMatchExactlyOneSub function recursive.) If you've done one, please post it.
PS3: Problem 4 » Solution
def subStringMatchExactlyOneSub( key, target ):
    subOneMatches = sorted(subStringMatchOneSub( key, target ))
    exactMatches = sorted(subStringMatchExact( target, key ))
    exactOneMatches = ()
    for subOneMatch in subOneMatches:
        if subOneMatch not in exactMatches:
            exactOneMatches += subOneMatch,
    return exactOneMatches



