I am relatively new to python and especially recursion. I have been trying to solve this problem for a while now but it's bested me so far
I have to create a function that takes in 2 strings and uses recursion to see if elements from the first string are in the second string if so it returns true if not than it returns false say "Carpool" and "prlo" or "elephant" and "xph" in the first case the recursive argument would return True and in the second case it would return False.
This is what I've been trying to do. I set a count so that if the elements match I can increase it and at the end if it's equal to len(str2) then I print 2. The major problem is iterating through the 2 strings separately, any idea on how I should approach this?
def compare(str1,str2):
count = 0
if str1 == str2:
return "True"
elif str1[0] == str2[0]:
count = count + 1
return letCheck (str1[1:],str2)
elif str1[0] != str2[0]:
return letCheck (str1[1:],str2)
trueifstr1shares characters withstr2and count them as well?in, is there some requirement that prevents this?