ararik, please do not double post!
You are almost there, as slate says, simply sum up word counts and word lenghts:
myfile = open(filename, "r")
wordcount_sum = 0
wordlength_sum = 0
for line in myfile:
words = line.split()
# sum up the word counts
wordcount_sum += len(words)
for word in words:
# sum up the word lengths
wordlength_sum += len(word)
# invoke floating point division for Python versions < 3.0
wordlength_average = wordlength_sum/float(wordcount_sum)
Last edited by sneekula; May 30th, 2009 at 11:22 am.
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
Offline 2,413 posts
since Oct 2006