On Wed, Oct 26, 2016 at 04:29:13AM +0200, Mikhail V wrote:
I need translate() which drops non-defined chars. Please :) No optimisation, no new syntax. deal?
I still wonder whether this might be worth introducing as a new string method, or an option to translate. But the earliest that will happen is Python 3.7, so in the meantime, something like this should be enough:
# untested keep = "abcdßαβπд∞" text = "..." # Find all the characters in text that are not in keep: delchars = set(text) - set(keep) delchars = ''.join(delchars) text = text.translate(str.maketrans("", "", delchars))