Reputation: 1
I'm still quite new to recursion and unable to figure out how to return a single boolean in my code. When left and right executes each will produce True or False, but how do i return a single boolean based on bool from left and bool from right?
def is_regex(s: str) -> bool:
bar_and_nodes = []
parentheses = []
node = 0
if len(s) == 1:
return s == '0' or s == '1' or s == '2' or s == 'e'
#omitted code
if s[-1] == ')':
# omitted code
if node > len(s) // 2:
split = s[1:-1].rsplit(s[node], 1)
left = is_regex(split[0])
right = is_regex(split[1])
else:
split = s[1:-1].split(s[node], 1)
left = is_regex(split[0])
right = is_regex(split[1])
# want to return left and right
Thanks!
Upvotes: 0
Views: 311
Reputation: 736
You need to return an and
on left
and right
because if either left
or right
is not a regex, the whole thing is not a regex.
Upvotes: 0