The first way is you can use regular expression’s (A regular expression in a programming language is a special text string used for describing a search pattern.) method re .findall().
In a regular expression, we use two expressions that search pattern, those expressions are “^” and “w+”.
re.findall():-
The re.findall() module is used when you want to iterate over the lines of the file, it will return a list of all the matches in a single step.
import re
string = "Hey, you - what are you doing here!?"
print(re.findall(r"[\w']+", string))
We can use a string method to solve this problem which is as follows.
import string
punc= string.punctuation
thestring = "Hey, you - what are you doing here!?"
s = list(thestring)
''.join([o for o in s if not o in punc]).split()