Question: Write Python code to determine exactly how long the first sentence of the novel is by: identify the index of the first sentence-ending punctuation (via
Write Python code to determine exactly how long the first sentence of the novel is by:
- identify the index of the first sentence-ending punctuation (via Python code, not by manual counting),
- retain only the slice of text before that index, and
- split the slice into words. This gives you a list. Count words by determining the length of the list.
Or you can
- Split the text into words, and
- count until you encounter a word ending in a sentence-ending punctuation.
If you want to go the latter route, it will be useful to know that the command break, written inside a loop, lets you exit the loop immediately.
mytext = """It was a dark and stormy night; the rain fell in torrents, except at occasional intervals, when it was checked by a violent gust of wind which swept up the streets (for it is in London that our scene lies), rattling along the house-tops, and fiercely agitating the scanty flame of the lamps that struggled against the darkness. Through one of the obscurest quarters of London, and among haunts little loved by the gentlemen of the police, a man, evidently of the lowest orders, was wending his solitary way. He stopped twice or thrice at different shops and houses of a description correspondent with the appearance of the quartier in which they were situated, and tended inquiry for some article or another which did not seem easily to be met with. All the answers he received were couched in the negative; and as he turned from each door he muttered to himself, in no very elegant phraseology, his disappointment and discontent. At length, at one house, the landlord, a sturdy butcher, after rendering the same reply the inquirer had hitherto received, added, But if this vill do as vell, Dummie, it is quite at your sarvice! Pausing reflectively for a moment, Dummie responded that he thought the thing proffered might do as well; and thrusting it into his ample pocket, he strode away with as rapid a motion as the wind and the rain would allow. He soon came to a nest of low and dingy buildings, at the entrance to which, in half-effaced characters, was written Thames Court. Halting at the most conspicuous of these buildings, an inn or alehouse, through the half-closed windows of which blazed out in ruddy comfort the beams of the hospitable hearth, he knocked hastily at the door. He was admitted by a lady of a certain age, and endowed with a comely rotundity of face and person."""
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
