Andy
Posts: 28
Nickname: adn
Registered: Jul, 2004
|
|
Re: help...
|
Posted: Apr 1, 2005 5:22 AM
|
|
The number of words would be pretty straightforward, assuming that they're seperated only by spaces;
>>> len("here are my words".split())
4
So you just have to read all the words from the file, either all at once if the file isn't too big or do it line by line and count the number of words on each line, keeping a total.
For the second problem, you could split the file into words, and then (pseudo code)
for each word: add 1 to our sentence length if the word ends with ('.', '?', '!' etc.): put the sentence length onto the end a list of lengths set the sentence length counter back to 0.
You should then end up with a list of lengths, e.g. [11,5,9] would mean a file with sentences with 11, 5 then 9 words in.
But I'll leave the exact Python to you.
|
|