Hi I am in problem set 3. The code I wrote for question 1 is def countSubStringMatchRecursive(target,key): k=find(target,key) if k==-1: n=0 return n else: m=target[k+1:] n=1+countSubStringMatchRecursive(m,key) return n It only gives me 0 when there's no match or 1 when there is. But cannot give me those more than one. Anything wrong in the code? Thanks a lot~
For me the code works just fine
Thanks~I know the problem now When we do string slicing, it does not change. So instead of having m=target[k+1:] I should have m=m[k+1:]
@verbit is right, the code works fine just the way it is. If you write m = m[k+1:], you will get an error since m has not been defined before. So, it should be m = target[k+1] as mentioned before.
Join our real-time social learning platform and learn together with your friends!