| |
comp.lang.python |
In article <1180965792.757685.132...@q75g2000hsh.googlegroups.com>, >import re
Adam Atlas <a...@atlas.st> wrote:
>still a one-liner. Untested, but I think this should work:
>from htmlentitydefs import name2codepoint
>def htmlentitydecode(s):
> return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m:
>name2codepoint[m.group(1)], s)
import re
from htmlentitydefs import name2codepoint
def htmlentitydecode(s):
return re.sub('&(%s);' % '|'.join(name2codepoint), lambda m: chr(name2codepoint[m.group(1)]), s)
We're stretching the limits of what's comfortable
for me as a one-liner.
B. How's it happen this isn't in the Cookbook? I'm
curious about what other Pythoneers think: is
this better memorialized in the Cookbook or the
Wiki?