I am very new to Python and computer programming language. I have been working on a text file where I want to find the average length of words in a text file. Well, to start with:
Let's say I have only one sentence in my text file (we can worry about the multiple sentences later). Here's the text:
"But Buffet wrote that he remains hopeful about the long-term prospects for his company and the nation despite the turmoil shaking the world's economies."
I can find the length of each word in this sentence by using the following code;
>>> myfile = open("c:/test/oneline.txt","r")
>>> for line in myfile:
... wordcounts = len(words)
... for word in words:
... lengthword = len(word)
... print lengthword
which gives me
....and so on.
My problem is writing the rest of the code i.e. summing this up and dividing it by the total number of words.
Thanks in advance.