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
Post a Comment