fork(1) download
  1. #!/usr/bin/env python3
  2.  
  3. def substr_index(substr, string, start=0):
  4.  
  5. end = start + len(substr)
  6.  
  7. if end > len(string):
  8. return None
  9.  
  10. target = string[start:end]
  11.  
  12. if substr == target:
  13. return start
  14.  
  15. else:
  16. return substr_index(substr, string, start+1)
  17.  
  18. print('result:', substr_index('y', 'foobarbazy'))
  19. print('result:', substr_index('bar', 'foobarbazy'))
  20. print('result:', substr_index('baz', 'foobarbazy'))
  21. print('result:', substr_index('', 'foobarbazy'))
  22.  
Success #stdin #stdout 0.03s 9984KB
stdin
Standard input is empty
stdout
result: 9
result: 3
result: 6
result: 0