Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner: remove numbers! Compare Brackets ¯\_( ͡▀̿ ̿ ͜ʖ ͡▀̿ ̿ )_/¯ solution in Speedy category for Brackets by Stensen
def checkio(exp):
m, match, count = [], [], {i: exp.count(i) for i in '[{()}]'}
for i, b in enumerate(exp):
if b == '(' and count[')'] >= m.count(b) + 1: m.extend([b, i])
elif b in '[{' and count[chr(ord(b)+2)] >= m.count(b) + 1: m.extend([b, i])
elif b in ")}]" and m and abs(ord(b) - ord(m[-2])) <= 2: match.extend([(i, b), (m.pop(), m.pop())])
return ''.join(([i for i in exp if i in '[{()}]'])) == ''.join([i for _, i in sorted(match)])
Oct. 23, 2020