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

Hi all, working on problem set 3 part 2. Keep getting stuck in a loop if there is more than one match. ``` def subStringMatchExact(x, y): total_count = 0 n = 0 results = () while find(x[n:], y) >= 0: # while there is a match new_n = find(x[n:], y) # attribute a new value of n print new_n results.append(new_n) # add the match to the results tuple n = new_n + 1 # change n to the new value total_count += 1 # add 1 to the total matches print total_count return results ``` It seems to change the string length when the start position changes.

OpenStudy (e.mccormick):

Well, the string length being compared will change. You are passing a shorter sub string. You need to account for the fact that you are not starting at 0 when you advance.

OpenStudy (anonymous):

Thanks. Working now as intended.

OpenStudy (e.mccormick):

=)

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!