Skip to content

Instantly share code, notes, and snippets.

@josephcc
Created November 22, 2013 20:38
Show Gist options
  • Save josephcc/7606454 to your computer and use it in GitHub Desktop.
Save josephcc/7606454 to your computer and use it in GitHub Desktop.
import re
from sys import stdin
def uncnf(g):
return type(g) not in (list, tuple) and g or map(uncnf, g[g[0]=='<DEL>':])
for line in stdin:
line = re.sub(' +', ',', re.sub('([^() ]+)', r"'\1'", re.sub('([()])', r' \1 ', line).strip()))
line = eval(re.sub(r'\[X[1-9][0-9]*\]', '<DEL>', line.replace('(,', '(')))
print uncnf(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment