I have a list of strings and I want to remove specific elements in each string from it. Here is what I have so far:
s = [ "Four score and seven years ago, our fathers brought forth on",
"this continent a new nation, conceived in liberty and dedicated"]
result = []
for item in s:
words = item.split()
for item in words:
result.append(item)
print(result,'\n')
for item in result:
g = item.find(',.:;')
item.replace(item[g],'')
print(result)
The output is:
['Four', 'score', 'and', 'seven', 'years', 'ago,', 'our', 'fathers', 'brought', 'forth', 'on', 'this', 'continent', 'a', 'new', 'nation,', 'conceived', 'in', 'liberty', 'and', 'dedicated']
In this case I wanted the new list to contain all the words, but it should not include any punctuation marks except for quotes and apostrophes.
['Four', 'score', 'and', 'seven', 'years', 'ago', 'our', 'fathers', 'brought', 'forth', 'on', 'this', 'continent', 'a', 'new', 'nation', 'conceived', 'in', 'liberty', 'and', 'dedicated']
Even though am using the find function the result seems to be same. How can I correct it prints without the punctuation marks? How can I improve upon the code?