问题遇到的现象和发生背景
请问谁能说明一下POP()函数可以在if的条件里运行?
if dic[stack.pop()] != c: # pop命令可以在if条件句里运行
用代码块功能插入代码,请勿粘贴截图
s = '{{[[(]]}()}'
def isvalid( s):
dic = {'{': '}', '['::']', '(': ')', '?': '?'}
stack = ['?']
for c in s:
if c in dic:
print(c)
stack.append(c)
print(stack)
elif dic[stack.pop()] != c: # pop命令可以在if条件句里运行
print(stack+['!'])
return False
return len(stack) == 1
l = isvalid(s=s)
print(l)