[Python-ideas] in str.replace(old, new), allow 'old' to accept a tuple
INADA Naoki
songofacandy at gmail.com
Thu Apr 12 18:32:58 CEST 2012
Yes, I know it.
But if str.replace() or str.translate() can do it, it is simpler and
faster than re.sub().
On Fri, Apr 13, 2012 at 1:20 AM, Sven Marnach <sven at marnach.net> wrote:
> INADA Naoki schrieb am Thu, 12. Apr 2012, um 22:17:30 +0900:
>> Oh, I didn't know that. Thank you.
>> But what about unescape? str.translate accepts only one character key.
>
> You'd currently need to use the `re` module:
>
> >>> d = {"&": "&", ">": ">", "<": "<"}
> >>> re.sub("|".join(d), lambda m: d[m.group()], "<>&")
> '<>&'
>
> Cheers,
> Sven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
--
INADA Naoki <songofacandy at gmail.com>
More information about the Python-ideas
mailing list