Skip to content

Instantly share code, notes, and snippets.

@maciejczyzewski
Created May 4, 2016 23:29
Show Gist options
  • Save maciejczyzewski/f12d884ff184cfbee1d0f1bb3c66b294 to your computer and use it in GitHub Desktop.
Save maciejczyzewski/f12d884ff184cfbee1d0f1bb3c66b294 to your computer and use it in GitHub Desktop.
def f(l, o='{}'):
s=[[]]
def x(): s[-1].append([]); s.append(s[-1][-1])
def y(): return -1 if len(s) == 1 else s.pop()
for c in l:
try:
if { o[0]: x, o[1]: y }[c]() == -1: return False
except KeyError: s[-1].append(c)
return s[0] if len(s) == 1 else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment