# import lib
# def function
def Bracket_Matching(param):
symbol = {"}": "{", "]": "[", ")": "("}
symbol_L = symbol.values()
symbol_R = symbol.keys()
temp = []
for i in param:
#进栈
if i in symbol_L:
temp.append(i)
elif i in symbol_R:
# 要么出栈,要么出错
if temp and temp[-1] == symbol[i]:
temp.pop()
else:
return False
#"["
if len(temp)==0:
return True
else:
return False
# main
if __name__ == "__main__":
# example = input()
example = "["
example1="3 * {3 +[(2 -3) * (4+5)]}"
result = Bracket_Matching(example)
result1 = Bracket_Matching(example1)
print(result,result1)
输出结果:
False True