I just did ps3a and I created the iterative function. It works but if anyone has any suggestions on how to improve it and clean it up, please let me know. http://dpaste.com/hold/694021/
Ok! This is what I got for ps3a. I´m not sure if I understood correctly what it is that it asked for, since it was way too easy, in comparison to the last assignments, to get to it. def countSubStringMatch(target, key): x = target y = key z = 0 ctr = 0 while find(x,y, z) != -1: if find(x,y,z) == z: ctr += 1 z += 1 print ctr Can anyone please enlighten me on what it is that needs to be done so that I can get my butt kicked like I´m supposed to?
Oh! And while I´m at it, here´s my answer to PS3b: def SubStringMatchExact(target, key): x = target y = key z = 0 while find(x,y, z) != -1: if find(x,y,z) == z: print z z += 1 Again... I´m pretty sure I´m not doing what they´re asking of me. Can anyone help?
EFarias: your implementations give the right results, so it"s ok. Don't worry about the difficulty, the maths will come back soon ! Just a few notes: 1. You don't have to rename the parameters. Just use target and key in the function. 2. For substringMatchExact (but I guess it makes sense for the other functions too), you should return a value, not print it. 3. Your code is not very efficient, since in the while loop you are searching a first time for the key from pos z, if you find it, you continue to search it until the position where key is found is equal to z, incrementing z by 1 each time. You could do better by setting z to the right position.
what is your code for the recursive part of this same question
Join our real-time social learning platform and learn together with your friends!