[issue26464] str.translate() unexpectedly duplicates untranslated characters

Ben Knight report at bugs.python.org
Tue Mar 1 08:51:44 EST 2016


New submission from Ben Knight:

Python 3.5.1 x86-64, Windows 10

I created a translation map that translated some characters to None and others to strings and found that in some cases str.translate() will duplicate one of the untranslated characters in the returned string.

How to reproduce:

table = str.maketrans({'a': None, 'b': 'cd'})
'axb'.translate(table)

Expected result:

'xcd'

Actual result:

'xxcd'

Mapping 'a' to '' instead of None will produce the desired effect.

----------
messages: 261049
nosy: ben.knight
priority: normal
severity: normal
status: open
title: str.translate() unexpectedly duplicates untranslated characters
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26464>
_______________________________________


More information about the Python-bugs-list mailing list