How to convert a string to a list of words without punctuation in Python

Converting a string to a list of words parses the string for words and adds them to a list. For example, converting “Th!is ?is a$ s#en!!te?!nce.” to a list of words results in [“This”, “is”, “a, “sentence”].

Solution for How to convert a string to a list of words without punctuation in Python : You can use re.sub(), and str.split() to convert a string to a list of words without punctuation Call re.sub(pattern, repl, string) with the regular expression “[^\w\s]” as pattern, “” as repl, and the string to convert as string to return a new string without any punctuation marks. Call str.split() with the new string as str to convert it to a list of words.


how-to-convert-a-string-to-a-list-of-words-without-punctuation-in-python