📜  平衡括号python代码示例

📅  最后修改于: 2022-03-11 14:45:05.234000             🧑  作者: Mango

代码示例1
o=['[','{','(']
c=[']','}',')']

def check(s):
    a=[]
    for i in s:
       
        if i in o:
             a.append(i)
        elif i in c:
            pos=c.index(i)
            if((len(a)>0)and(o[pos]==a[len(a)-1])):
                a.pop()
            else:
                return "Unbalaced"
    if len(a)==0:
        return "bal"
    else:
        return "Unbal"
            

s='{{[])}}'
string=check(s)
print(string)