Author Jim.Jewett
Recipients Jim.Jewett, docs@python
Date 2016-11-04.17:02:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1478278954.92.0.793705359912.issue28612@psf.upfronthosting.co.za>
In-reply-to
Content
One commonly needed string transformation is stripping out certain characters (or only keeping certain characters).  This is common enough that it might be worth a dedicated method, except, that, as Stephen J. Turnbull wrote in https://mail.python.org/pipermail/python-ideas/2016-November/043501.html

"""
So really translate with defaultdict is a specialized loop that
marries an algorithmic body (which could do things like look up the
original script or other character properties to decide on the
replacement for the generic case) with a (usually "small") table of
exceptions.  That seems like inspired design to me.
"""

Alas, while inspired, it isn't obvious to someone who isn't yet used to the power of python custom classes.

The documentation (such as https://docs.python.org/3/library/stdtypes.html?highlight=translate#str.translate ) should include such an example.

One possible example would be a defaultdict that says to discard any characters except lower case ASCII lettersI.
History
Date User Action Args
2016-11-04 17:02:34Jim.Jewettsetrecipients: + Jim.Jewett, docs@python
2016-11-04 17:02:34Jim.Jewettsetmessageid: <1478278954.92.0.793705359912.issue28612@psf.upfronthosting.co.za>
2016-11-04 17:02:34Jim.Jewettlinkissue28612 messages
2016-11-04 17:02:34Jim.Jewettcreate