Why would you like to replace words like food, help, work or love with xxxx?
Lardmeister
Posting Virtuoso
1,749 posts since Mar 2007
Reputation Points: 407
Solved Threads: 44
I think it goes like that:
text = "I love to work and pay my taxes!"
# text to list
words = text.split()
print words # ['I', 'love', 'to', 'work', 'and', 'pay', 'my', 'taxes!']
# list to text
print ' '.join(words) # I love to work and pay my taxes!
Lardmeister
Posting Virtuoso
1,749 posts since Mar 2007
Reputation Points: 407
Solved Threads: 44
I think it would be easier, if you ...
1) read the file in as a string
2) convert to a list of words
3) process each word in the list
4) create a new list of the process results
5) join the new list back to a string
6) save this modified string to a file
You have pretty much accomplished items 1, 2 and 3
If you want to retain the punctuation marks in the modified text, you have to put your thinking cap on! This will be a challenge!
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417