Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Brackets by twilyght
OPENING = '{[('
CLOSING = '}])'
PAIRS = {x: y for x, y in zip(CLOSING, OPENING)}
def checkio(expression):
brackets = [c for c in expression if c in OPENING + CLOSING]
stack = []
for c in brackets:
if c in OPENING:
stack.append(c)
elif not stack or PAIRS[c] != stack.pop():
return False
return stack == []
May 13, 2020
Comments: