Created
May 4, 2016 23:29
-
-
Save maciejczyzewski/f12d884ff184cfbee1d0f1bb3c66b294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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