New submission from bob gailer:

Documentation for str.translate only mentions a dictionary for the translation 
table. Actually any iterable can be used, as long as its elements are integer, 
None or str.

Recommend wording:


Return a copy of the s where all characters have been "mapped" through the 
translation_table - which must be either a dictionary mapping Unicode ordinals 
(integers) to Unicode ordinals, strings or None,
or an iterable. In this case the ord() of each character in s is used as an 
index into the iterable; the corresponding element of the iterable replaces the 
character. If ord() of the character exceeds the index range of the iterator, 
no substitution is made.

Example: to shift any of the first 255 ASCII characters to the next:

>>> 'Now is the time for all good men'.translate(range(1, 256))

COMMENT: I placed mapped in quotes as technically this only applies to 
dictionaries. Not sure what the best word is.

assignee: docs@python
components: Documentation
messages: 216630
nosy: bgailer, docs@python
priority: normal
severity: normal
status: open
title: str.translate documentation incomplete
type: enhancement
versions: Python 3.3

Python tracker <>
Python-bugs-list mailing list

Reply via email to