Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ord(bracket) solution in Clear category for Brackets by V.Shkaberda
def checkio(expression):
xpr = ''.join(c for c in expression if c in ('([{}])'))
test = [0] # digit to avoid IndexError
for bracket in xpr:
if bracket in '([{': # open bracket
test.append(ord(bracket))
elif not abs(test.pop() - ord(bracket)) < 3:
return False # if bracket isn't closed properly
return test[-1] == 0 # no brackets remain?
May 9, 2019
Comments: