NEED HELP-process words in a text file


Cathy James

Dear Python Experts,

First, I'd like to convey my appreciation to you all for your support
and contributions. I am a Python newborn and need help with my
function. I commented on my program as to what it should do, but
nothing is printing. I know I am off, but not sure where. Please

import string
def fileProcess(filename):
"""Call the program with an argument,
it should treat the argument as a filename,
splitting it up into words, and computes the length of each word.
print a table showing the word count for each of the word lengths
that has been encountered.
Length Count
1 16
2 267
3 267
4 169Length Count
0 0Length Count
5 10
freq = [] #empty dict to accumulate words and word length
filename=open('declaration.txt, r')
for line in filename:
punc = string.punctuation + string.whitespace#use Python's
built-in punctuation and whiitespace
for i, word in enumerate (line.replace (punc, "").lower().split()):
if word in freq:
freq[word] +=1 #increment current count if word already in dict

freq[word] = 0 #if punctuation encountered,
frequency=0 word length = 0
for word in freq.items():
print("Length /t"+"Count/n"+ freq[word],+'/t' +
len(word))#print word count and length of word separated by a tab

#Thanks in advance,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question