I have a file from which I read a set of words, this file is "file1.txt".
The content for example of "file1.txt" file is the following:
Hello how are you? Very good!
What I have to do eliminate those symbolic characters that appear in the example.
For the previous example, the final phrase would be the following:
Hello how are you Very good
My idea was, once I have read all the words, store them in a list to apply the corresponding "replace" to remove all types of invalid characters.
Another idea that I thought, is when I load the .txt file directly apply the replace there, however after trying different ways I do not apply the deletion of the invalid characters.
Here is my code:
# -*- coding: utf-8 -*-
import sys
def main():
characters = '!?¿-.:;'
aux = []
with open('file1.txt','r') as f:
for line in f:
for word in line.split():
aux.append(word)
for a in aux:
for character in characters:
a = a.replace(character,"")
if __name__ == '__main__':
main()
As you can see, the first part of my code stores in a list called 'aux' all the words from the txt file.
But I dont know how to apply "replace" method to eliminate the invalid characters from my words.