Created
November 23, 2013 23:15
-
-
Save josephcc/7621245 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from re import * | |
| from sys import stdin | |
| uncnf = lambda g: g if type(g) == str else tuple(map(uncnf, g[match(r'\[X[1-9][0-9]*\]', g[0])!=None:])) | |
| pyfy = lambda l: eval((sub('([^ (]) +', r'\1,', sub('([^() ]+)', r'"\1"', sub('([()])', r' \1 ', l).strip())))) | |
| def _clean(g): | |
| for gg in g: | |
| if str in (type(gg), type(gg[0])): | |
| yield gg | |
| else: | |
| for ggg in gg: | |
| yield ggg | |
| clean = lambda g: g if type(g) == str else tuple(map(clean, _clean(g))) | |
| for l in stdin: | |
| print str( clean(uncnf(pyfy(l))) ).replace("'", '').replace(',','') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment