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 Chris.Barker
Recipients Chris.Barker, ChrisBarker, Gaurav Tatke, Jim.Jewett, docs@python, rhettinger, serhiy.storchaka
Date 2016-12-30.23:40:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In-reply-to <>
This all came out of a thread on python-ideas, starting here:

the thread kind of petered out, but it seems there was a kinda-sorta
consensus that we didn't need any new string methods, but rather same notes
in the docs on how to to use .translate() to remove "all but these" was in

And the defaultdict method was proposed as the easiest / most pythonic.

As it happens, I did't live the fact hat defaultdict will build up a
big(ish) dict of Nones for no reason, and thus suggested a NoneDict option:

class NoneDict(dict):
    Dictionary implementation that always returns None when a key is not in
the dict,
    rather than raising a KeyError
    def __getitem__(self, key):
            val = dict.__getitem__(self, key)
        except KeyError:
            val = None
        return val

Though maybe that's a bit much for the docs.

However, in short:

either the defaultdict approach is siple and pythonic enough to be in teh
docs, or we SHOULD add something new to the string object.

(or maybe someone has another nifty pythonic way to do this with the stdlib
that's better than defaultdict?)


On Fri, Dec 30, 2016 at 12:18 PM, Gaurav Tatke <>

> Gaurav Tatke added the comment:
> Should a user be suggested to use str.translate() for the use case where
> user only wants to keep certain characters and strip off everything else?
> ----------
> _______________________________________
> Python tracker <>
> <>
> _______________________________________


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception
Date User Action Args
2016-12-30 23:40:16Chris.Barkersetrecipients: + Chris.Barker, rhettinger, docs@python, Jim.Jewett, serhiy.storchaka, ChrisBarker, Gaurav Tatke
2016-12-30 23:40:16Chris.Barkerlinkissue28612 messages
2016-12-30 23:40:16Chris.Barkercreate