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

Working on ps3 problem 1 (the iterative function): I think I have the basic idea of how it works but my code is doing something funny. Any clues on how to tweak it to make it work would be much appreciated. http://codepad.org/lRGrwQFQ

OpenStudy (anonymous):

So I think I actually fixed it. But there has to be a better way. Any suggestions?

OpenStudy (anonymous):

Uhm, if you made changes, can you post the updated code?

OpenStudy (anonymous):

You probably already noticed, but you may begin subsequent searches at the index of the match+1. For example, the first find of "a" in "banana" will return 1. You may then set your next search up to begin at index 2. Something similar to this: http://codepad.org/aLhvRQuV

OpenStudy (anonymous):

kgiax: I thought I did, but I misunderstood how codepaste works. Here is what I came up with to fix it: http://codepad.org/YOc7FM6n

OpenStudy (anonymous):

walkerp1: I think my fix does that, but not as elegantly. I think there is some redundancy in the n and x of my current code.

OpenStudy (anonymous):

kgiax + walkerp1: newest and I think final verison: http://codepad.org/g5GtrURI Last question regarding this. When "print codeSubStringMatch("anything","key")" is put in, why is it returning None after the "There are x instances...They are..."?

OpenStudy (anonymous):

you need to return something at the end of your function like return matches you can return multiple things return matches, matchesLoc here is another way to keep the while loop going http://ideone.com/OcPXU

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!