Untitled

Anonymous
plain_text
10/17/2023 10:48 AM
468 B
20
Indexable
stack=[]
st = "(([]))"
for item in st:
    if item=="(" or item=="[":
        print(1)
        stack.append(item)
    elif item=="]" and stack[-1]== "[":
        print(2)
        stack.pop(-1)
    elif item==")" and stack[-1]=="(":
        print(3)
        stack.pop(-1)
    else: 
        print("bad input")
        break
print(stack)
Editor is loading...