Thanks all. Pydoc is Really unclear on that. It makes it look like it replaces all characters.
strip(...)
S.strip([chars]) -> str
Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
(Dec-26-2018, 10:28 PM)snippsat Wrote: Can do it like this.
>>> from string import punctuation
>>>
>>> s = "All.Good,Dogs.. Eat.! Shoes?"
>>> ''.join(c for c in s if c not in punctuation)
'AllGoodDogs Eat Shoes'
Or specify yourself what to remove.
>>> s = "All.Good,Dogs.. Eat.! Shoes?"
>>> "".join(c for c in s if c not in list(',.!'))
'AllGoodDogs Eat Shoes?'
That looks like a list comprehension. I thought you had to use square brackets for that. ie:
import string
dogs = 'My., bad? dog - eats,,.. shoes*'
''.join([dog for dog in dogs if dog not in string.punctuation])
By the way, where two words were joined with punctuation and no space they were mashed together, but if I join with spaces I get too many. What's the best way to turn multiple spaces into one?