Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7930 > unrolled thread

NEED HELP-process words in a text file

Started byCathy James <nambo4jb@gmail.com>
First post2011-06-18 18:21 -0500
Last post2011-06-18 18:21 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  NEED HELP-process words in a text file Cathy James <nambo4jb@gmail.com> - 2011-06-18 18:21 -0500

#7930 — NEED HELP-process words in a text file

FromCathy James <nambo4jb@gmail.com>
Date2011-06-18 18:21 -0500
SubjectNEED HELP-process words in a text file
Message-ID<mailman.133.1308439317.1164.python-list@python.org>
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
help:(

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.
    Example:
    Length Count
    1 16
    2 267
    3 267
    4 169
    >>>"&"
    Length    Count
    0    0
    >>>
    >>>"right."
    Length    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

            else:
                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,
CJ.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web