class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
opening_brackets = ['[', '(', '{']
closing_brackets = [']', ')', '}']
top = dict(zip(opening_brackets, closing_brackets))
stack = []
for i in s:
if i in opening_brackets:
stack.append(top[i])
elif i in closing_brackets:
if len(stack)!=0 and i == stack[len(stack)-1]:
stack.pop()
else:
return False
if len(stack) == 0:
return True
else:
return False
if __name__ == "__main__":
s = Solution()
string = '[{(})}]'
print(s.isValid(string))