[Python-ideas] in str.replace(old, new), allow 'old' to accept a tuple

Sven Marnach sven at marnach.net
Thu Apr 12 15:10:23 CEST 2012


INADA Naoki schrieb am Thu, 12. Apr 2012, um 20:32:45 +0900:
> >>> "<>&".replace( ('<', '<'), ('>', '>'), ('&', '&') )
> '<>&'

In current Python, it's

    >>> t = str.maketrans({"<": "<", ">": ">", "&": "&"})
    >>> "<>&".translate(t)
    '<>&'

Looks good enough for me.

Cheers,
    Sven



More information about the Python-ideas mailing list