On 2018-05-10, Albert-Jan Roskam <sjeik_ap...@hotmail.com> wrote:
> If a punctuation symbol is in your string:  Replace that symbol
> with an empty string.
>
>=>>> maybe something like
>
> import re
> no_interpunction = re.sub("[%s]" % re.escape(string.punctuation), '', 
> sentence)

str.translate can be used instead of re.

# Compute only once somewhere
punctuation_removal_table = str.maketrans({c: None for c in string.punctuation})


    no_interpunction = sentence.translate(punctuation_removal_table)

Unfortunately you'll remove all the apostrophes and dashes, both
of which could be considered parts of words.

-- 
Neil Cerutti

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to