python - string recursion problems -


I'm relatively new to Python and especially recursive. I am trying to solve this problem for a little while, but I have been made better so far

I have to create a function that takes 2 strings and see if The elements of the first string are the second string, if this happens, then it returns true if it is not wrong, then "carpool" and "prolo" or "elephant" and "xf" in the first case the recurring logic will return the truth and the second Matters It would be wrong. / P>

This is what I am trying to do. I have calculated a number that if I match the elements then I can increase it and in the end if this is equal to the lane (str2), then i print 2. The big problem runs separately from 2 strings, how should I know this?

Compare DRF (SR1, SR2):

  count = 0 if str1 == str2: return "true" aliha str1 [0] == str2 [0]: Count = count + 1 return LetCheck (str1 [1:], str2) elif str1 [0]! = Str2 [0]: Return LetCheck (str1 [1:], str2)  

  Compare df (S1, S2): If not s2: Return Elif S2 [0] in s1: Compare Returns (S1, S2 [1:]) and: return false  

On your examples:

  & gt; & Gt; & Gt; Compare ("Carpool", "Prello") True & gt; & Gt; & Gt;  

How it works

Function performs the function of each character in string 2, s2 ("elephant", "xph" ) Compare one at a time. There are three cases:

  1. If any letter is not processed in s2 , then that means all the tests have passed and we return the truth . / P>

  2. If we still have left the letter s2 , then we test the s2 [0] if it passes So, we again use recycling to test the remaining strings.

  3. If s2 [0] is not s1 , then we have failed and we make false return.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -