Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
stack solution in Clear category for Brackets by ajx
def checkio(expression):
brackets = {'(' : ')', '{' : '}', '[' : ']'}
s = []
for i in expression:
if i in brackets:
# Opening bracket - push to stack
s.append(i)
elif i in brackets.values():
# Closing bracket - pop
try:
if brackets[s.pop()] != i:
return False
except:
return False
return len(s) == 0
Nov. 6, 2016