I have a file .txt and I want to travel through the words of it. I have a problem, I need to remove the punctuation marks before travelling through the words. I have tried this, but it isn't removing the punctuation marks.
for word in file.read().strip(",;.:- '").split():
The problem with your current method is that
.strip() doesn't really do what you want. It removes leading and trailing characters (and you want to remove ones within the text), and if you want to specify characters in addition to whitespace, they need to be in a list.
Another problem is that there are many more potential punctuation characters (question marks, exclamations, unicode ellipses, em dashes) that wouldn't get filtered out by your list. Instead, you can use
string.punctuation to get a wide range of characters (note that
string.punctuation doesn't include some non-English characters, so its viability may depend on the source of your input):
import string punctuation = set(string.punctuation) text = ''.join(char for char in text if char not in punctuation)
import string text = text.translate(string.maketrans('', ''), string.punctuation)