Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

For efficiency I suggest to initialize the mapping with 
dict.fromkeys(range(128), 'x') rather of an empty dict.

It is also possible to use regular expressions:

_trans = re.compile(r'''[^(){}\[]"'\\\n#]+''')
code = _trans.sub('x', code)
code = code.replace('{', '(')
code = code.replace('}', ')')
code = code.replace('[', '(')
code = code.replace(']', '(')
code = code.replace('\nx', '\n')

I didn't check what way is more efficient.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32940>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to