Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Brackets by panther-king
def checkio(expression):
BRACKETS = {'{': '}',
'(': ')',
'[': ']'}
opens = []
def get_pair(close):
pair = None
for k, v in BRACKETS.items():
if v == close:
pair = k
break
return pair
for c in expression:
if c in BRACKETS.keys():
opens.append(c)
elif c in BRACKETS.values():
if not opens:
return False
elif not get_pair(c) == opens[-1]:
return False
else:
opens.pop()
return True if not opens else False
#These "asserts" using only for self-checking and not necessary for auto-testing
May 8, 2014