How do you remove punctuation from a list using a for loop? I have imported a string of punctuation and I am using this to compare to the original list in order to remove the punctuation.
This is my current code:
import string
l = list(string.punctuation)
print(punctuation_list)
w = ["haythem", "is", "eating", "tacos.", "haythem", "loves", "tacos", "", ":"]
w_clean = list()
for x in w:
for y in l:
if y in x:
x = x.replace(y,'')
w_clean.append(x)
break
print(w_clean)
And the output is:
['!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~']
['tacos', '']
The required output is:
['haythem', 'is', 'eating', 'tacos', 'haythem', 'loves', 'tacos']