def fun(s1, s2, i, j): if i < 0 and j < 0: return True if i < 0 and j >= 0: return False if j < 0 and i >= 0: for k in range(i + 1): if s1[k] != '*': return False return True if s1[i] == s2[j] or s1[i] == '?': return fun(s1, s2, i - 1, j - 1) if s1[i] == '*': return fun(s1, s2, i - 1, j) or fun(s1, s2, i, j - 1) return False s1 = "ab*" s2 = "abde" print(fun(s1, s2, len(s1) - 1, len(s2) - 1))