language: Python (python 2.7.3)
date: 332 days 19 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pprint
import re
import sys
 
data = sys.stdin.read()
 
exec (data.replace('(', 'dict(')) # use only for input that you control e.g., for unit-testing
pprint.pprint(abc)
 
def repl_flat(m):
    return "\n".join("<{0}>{1}</{0}>".format(*map(str.strip, s.partition('=')[::2]))
                     for s in m.group(1).split(','))
 
def eval_nested(expr):
    val, n = re.subn(r"\(([^)(]+)\)", repl_flat, expr)
    return val if n == 0 else eval_nested(val)
 
print eval_nested("(%s)" % (data,))