Im trying to make a function which looks through multiple parenthesis and returns the contents of each set of parenthesis from inside out. So given the input (9*(2*(6*6))), it would return
(6*6)
(2*(6*6))
(9*(2*(6*6)))
I have this so far but im not sure how to make it work for multiple pairs of brackets. It only return the inner most bracket.
def in_brackets(str) :
close_b = 0
open_b = 0
if len(str) < 5 :
return True
while str[close_b] != ')':
close_b += 1
if str[close_b] == '(':
open_b = close_b
in_b = str[open_b:close_b + 1]
return(in_b)