Untitled

 avatar
unknown
plain_text
2 years ago
350 B
5
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...