[Tutor] Stripping punctuation
W W
srilyk at gmail.com
Thu May 29 19:35:19 CEST 2008
Is there a faster way to strip punctuation from a string than this?
from string import ascii_letters
def strip_punctuation(mystring):
newstring = ''
for x in mystring:
if x in ascii_letters:
newstring += x
else:
pass
return newstring
In my decryption program I realized I need to strip all the
punctuation, and that's the first thing I came up with. I couldn't
find a built-in function in the time it took to roll my own.
TIA,
Wayne
--
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi
More information about the Tutor
mailing list