I wrote a recursive function to find the number of instances of a substring in the parent string.
The way I am keeping count is by declaring/initialising count
count
How about this?
def count_it(target, key): index = target.find(key) if index >= 0: return 1 + count_it(target[index+len(key):], key) else: return 0 print count_it("aaa bbb aaa ccc aaa", "aaa")
Output:
3