- #1
member 428835
Line 7 in the code below seems to remove an element from stack, but why is this happening since it's just checking a condition? I'm pretty shocked I don't have to remove the previous char from stack myself.
Python:
def isValid(s):
stack = []
dict = {"]":"[", "}":"{", ")":"("}
for char in s:
if char in dict.values():
stack.append(char)
elif stack == [] or dict[char] != stack.pop():
return False
return stack == []
if __name__ == "__main__":
s = "{([[{}]])}"
print(isValid(s))