I thinl there is problem with ps3_template.py???why?
I am also having trouble at the same place. My subStringMatchExact and constrainedMatchPair functions seem to give the correct output, but when I use the subStringMatchOneSub function provided in ps3_template.py I recieve no matches. Is there an error in the provided code?
I am going to post the code for the functions I created below: def subStringMatchExact(target,key): bookmark=0 location=() #While the find function does not fail to find a value while bookmark!=-1: #Store the index of the first match in bookbark. bookmark=find(target,key,bookmark) #Add bookmark to a tuple location=location+(bookmark,) #Find the next value of bookmark here so that if it is -1 we can stop before looping again. bookmark=find(target,key,bookmark+1) return location def constrainedMatchPair(firstMatch,secondMatch,length): listmatch=() for n in range(0,len(firstMatch)): for k in range(0,len(secondMatch)): if firstMatch[n]+length+1==secondMatch[k]: listmatch=listmatch+(firstMatch[n],) return listmatch
After putting some more work into this problem, I found my mistake. Perhaps this will help you too welldone_boy. The function given in the ps3_template asks you to input the key first, then the target (key, target). The previous functions that we created had us input in the reverse order (target,key).
I was able to complete the problem set last week with the function subStringMatchOneSub as defined in the template, there is no problem with it. Looking through your code I see a potential error your function constrainedMatchedPair. Be careful when using range(0,len(x)) in your loops, as the range function will cut off your last item: Yours: for n in range(0,len(firstMatch)): My suggestion: for n in firstMatch: Also, I suggest using pastepin.com for code sharing.
oocks, It is true that the parameters are reversed in subStringMatchOneSub. Good catch.
ohh good catch !I didn't noticed that..
when we use find(target,'') #empty string# it returns zero(0) but when we apply it(empty str) to subStringMatchExact we kinda run into infinite loop is there anyway to fix that bug?
Join our real-time social learning platform and learn together with your friends!