This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients bgailer, docs@python, martin.panter
Date 2014-04-17.04:50:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397710241.69.0.376564673868.issue21279@psf.upfronthosting.co.za>
In-reply-to
Content
I suspect “iterable” is the wrong term.

>>> isinstance(set(), Iterable)
True
>>> "abc".translate(set())
TypeError: 'set' object does not support indexing
>>> "abc".translate(object())
TypeError: 'object' object is not subscriptable

Maybe “indexable” or “subscriptable” would be more correct? If this behaviour is part of the API, it would be nice to document, because it would have saved me a few times from implementing the __len__() and __iter__() methods of the mapping interface in my custom lookup tables.

Here is my suggestion:

str.translate(table):

Return a copy of the string where all characters have been mapped through “table”, a lookup table. The lookup table must be a subscriptable object, for instance a dictionary or list, mapping Unicode ordinals (integers) to Unicode ordinals, strings or None. If a character is not in the table, the subscript operation should raise LookupError, and the character is left untouched. Characters mapped to None are deleted.
History
Date User Action Args
2014-04-17 04:50:41martin.pantersetrecipients: + martin.panter, bgailer, docs@python
2014-04-17 04:50:41martin.pantersetmessageid: <1397710241.69.0.376564673868.issue21279@psf.upfronthosting.co.za>
2014-04-17 04:50:41martin.panterlinkissue21279 messages
2014-04-17 04:50:41martin.pantercreate