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+”.
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.
string = "Hey, you - what are you doing here!?"
We can use a string method to solve this problem which is as follows.
thestring = "Hey, you - what are you doing here!?"
s = list(thestring)
''.join([o for o in s if not o in punc]).split()