I would like to know if this is a good approach to finding out all the expressions within brackets. (I was actually asked to find out the smallest bracket expression, I have omitted the function to check for the smallest string and spaces within the expression).
s = "((a+b*d)*(x/2))*(1+(y+(x-2)/10))"
b = []
j = 0
b.append(j)
stack = []
for i in range(0, len(s)):
if s[i] == '(':
j = j + 1
b.append(j)
b[j] = ''
elif s[i] == ')':
b[j] = b[j] + ')'
stack.append(b[j])
j = j - 1
# 0 is omitted to exclude characters outside of brackets
for k in range(1, j + 1):
b[k] = b[k] + s[i]
print(s)
print(stack)