Find a string in a string - Python -


i trying implement function find text in string recursively.

i tried this, don't know why it's not working. please note new coding.

def find(text, substring):   if len(text) == 0:      return 0   while substring[0] in text:      return find(text, substring[1:]) 

thanks! :)

example:

find("mississippi", "sip") true find("to or not be", "be") true find("mississippi", "sup") false 

you need base case recursive function return without recursing. base case len(text)==0 never executed unless text=='' first time through.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -