Below is the code that I am trying to execute: Recursively parse a string for a pattern that can be either 1 or 2 characters long.
def recur_parse(s,pattern):
result = False
print(s[0],s[0:2],result)
if s[0]==pattern or s[0:2]==pattern:
print('Condition Satisfied')
return True
elif len(s[1:]) >= len(pattern):
print('Calling the function recurisively with params',s[1:],pattern)
recur_parse(s[1:],pattern)
else:
return False
The expectation is that the recursive call should return a True, but it returns a False. Am I doing anything wrong?
The testcases execution for the same are below:
Case #1:
recur_parse('ximibi','xi')
('x', 'xi', False)
Condition Satisfied
=> True
Case #2:
recur_parse('ximibi','im')
('x', 'xi', False)
('Calling the function recurisively with params', 'imibi', 'im')
('i', 'im', False)
Condition Satisfied