[Tutor] Stripping punctuation

Kent Johnson kent37 at tds.net
Thu May 29 19:59:21 CEST 2008


On Thu, May 29, 2008 at 1:35 PM, W W <srilyk at gmail.com> wrote:
> Is there a faster way to strip punctuation from a string than this?

def strip_punctuation(my_string):
  return ''.join(c for c in my_string if c in ascii_letters)

or use str.translate():
http://docs.python.org/lib/string-methods.html#l2h-268

Kent


More information about the Tutor mailing list