
January 17th, 2013, 10:27 PM
|
 |
Contributing User
|
|
|
|
It's fairly easy in python. Run this code as an example. For a real application I'd want to be more careful about punctuation and capital letters to start sentences and two spaces or more separating sentences. Finding words was easy, removing some words was easy, and reformatting was easy.
Code:
import textwrap
#Madame Bovary
text = '''As she was a long time before she found
her work-case, her father grew impatient; she did not
answer, but as she sewed she pricked her fingers, which
she then put to her mouth to suck them. Charles was
surprised at the whiteness of her nails. They were shiny,
delicate at the tips, more polished than the ivory of
Dieppe, and almond-shaped. Yet her hand was not
beautiful, perhaps not white enough, and a little hard at
the knuckles; besides, it was too long, with no soft
inflections in the outlines. Her real beauty was in her eyes.'''
def filtered(s):
''' remove 3 letter "words" '''
words = s.split()
return ' '.join(word for word in words if len(word) != 3)
print(textwrap.fill(text, width=20))
print('\n'*3)
print(textwrap.fill(filtered(text), width=20))
__________________
[code] Code tags[/code] are essential for python code!
|