How do I skip over multiple words in a file?

r0g aioe.org at technicalbloke.com
Thu Nov 11 15:12:54 EST 2010


On 11/11/10 15:07, chad wrote:
> Let's say that I have an article. What I want to do is read in this
> file and have the program skip over ever instance of the words "the",
> "and",  "or", and "but". What would be the general strategy for
> attacking a problem like this?


If your files are not too big I'd simply read them into a string and do 
a string replace for each word you want to skip. If you want case 
insensitivity use re.replace() instead of the default string.replace() 
method. Neither are elegant or all that efficient but both are very 
easy. If your use case requires something high performance then best 
keep looking :)

Roger.



More information about the Python-list mailing list