1
입력 문자열에 괄호가있는 경우이 함수가 '참'을 반환 할 때 나는 이해하지 못합니다. 그것은 '진정한'을 어디에서 돌려 주는가?왜이 python 함수가 true를 반환합니까?
def balance_check(s):
if len(s)%2 !=0:
return False
opening = set('([{')
matches = set([('(',')'),('[',']'),('{','}')])
stack =[]
for paren in s:
if paren in opening:
stack.append(paren)
else:
if len(stack) == 0:
return False
last_open = stack.pop()
if (last_open,paren) not in matches:
return False
return len(stack) == 0
res=balance_check('[]')
방금 [pythontutor] (HTTP를 통해 실행하여 자신의 질문에 대답 할 수있을 : // pythontutor.com/visualize.html#) –