[Python-ideas] More user-friendly version for string.translate()
Stephen J. Turnbull
turnbull.stephen.fw at u.tsukuba.ac.jp
Wed Oct 26 14:24:52 EDT 2016
More information about the Python-ideas mailing list
Wed Oct 26 14:24:52 EDT 2016
- Previous message (by thread): [Python-ideas] More user-friendly version for string.translate()
- Next message (by thread): [Python-ideas] Showing qualified names when a function call fails
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Mikhail V writes:
> I need translate() which drops non-defined chars. Please :)
import collections
def translate_or_drop(string, table):
"""
string: a string to process
table: a dict as accepted by str.translate
"""
return string.translate(collections.defaultdict(lambda: None, **table))
All OK now?
- Previous message (by thread): [Python-ideas] More user-friendly version for string.translate()
- Next message (by thread): [Python-ideas] Showing qualified names when a function call fails
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list