Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Brackets by grazik
def checkio(expression):
open_bracket = ['{', '[', '(' ]
close_bracket = [ '}', ']', ')']
bracket = []
for i in expression:
if i in open_bracket or i in close_bracket:
bracket.append(i)
i = 0
while i < len(bracket) - 1:
if bracket[i] in open_bracket and bracket[i + 1] in close_bracket:
if open_bracket.index(bracket[i]) == close_bracket.index(bracket[i+1]):
del bracket[i]
del bracket[i]
i = 0
else:
return False
else:
i += 1
return True if len(bracket) == 0 else False
Oct. 29, 2016