I want to count the consecutive occurrences of a substring in a mainstring. After that, I want to take the number of consecutive occurrences, and have that as a return value. I wanted to do that recursively, as follows:
def countConsecutive (mainstr, substr, count):
if substr in mainstr[:len(substr)]:
count += 1
mainstr = mainstr[len(substr):]
countConsecutive (mainstr, substr, count)
else:
return count
I have 'count' as input, as it needs to be set to 0 every time the function is called outside the function itself. However, the problem is, the return value is a NoneType, so I can't compare it to the previous 'counts' to take the highest one. Why is it a NoneType?