Martin Panter added the comment:

I suspect “iterable” is the wrong term.

>>> isinstance(set(), Iterable)
>>> "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:


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.

nosy: +vadmium

Python tracker <>
Python-bugs-list mailing list

Reply via email to