[issue2650] re.escape should not escape underscore
Alexander Belopolsky
report at bugs.python.org
Thu May 8 16:08:29 CEST 2008
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
Lorenz's patch uses a set, not a list for special characters. Set
lookup is as fast as dict lookup, but a set takes less memory because it
does not have to store dummy values. More importantly, use of frozenset
instead of dict makes the code clearer. On the other hand, I would
simply use a string. For a dozen entries, hash lookup does not buy you
much.
Another nit: why use "\\%c" % (c) instead of obvious "\\" + c?
Finally, you can eliminate use of index and a temporary list altogether
by using a generator expression:
''.join(("\\" + c if c in _special else '\\000' if c == "\000" else c),
for c in pattern)
----------
nosy: +belopolsky
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2650>
__________________________________
More information about the Python-bugs-list
mailing list