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


Groups > comp.lang.python > #7930

NEED HELP-process words in a text file

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <nambo4jb@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'example:': 0.03; '"""': 0.07; '#if': 0.07; 'advance,': 0.07; 'subject:process': 0.07; 'tab': 0.07; 'python': 0.08; 'argument,': 0.09; 'dict': 0.09; 'splitting': 0.09; '>>>': 0.12; 'def': 0.12; 'skip:f 30': 0.14; 'subject:file': 0.14; 'computes': 0.16; 'encountered.': 0.16; 'filename,': 0.16; 'lengths': 0.16; 'newborn': 0.16; 'printing.': 0.16; 'argument': 0.16; 'do,': 0.25; 'string': 0.26; 'message-id:@mail.gmail.com': 0.28; 'import': 0.29; "python's": 0.29; 'subject:HELP': 0.29; 'received:209.85.215': 0.30; 'received:209.85.215.46': 0.30; 'received:mail-ew0-f46.google.com': 0.30; 'separated': 0.30; 'print': 0.31; 'word.': 0.32; 'words,': 0.32; 'to:addr:python- list': 0.33; 'skip:" 20': 0.33; 'showing': 0.34; 'function.': 0.35; 'subject:text': 0.36; 'table': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'skip:s 20': 0.39; 'should': 0.39; "i'd": 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'current': 0.40; 'help': 0.40; 'your': 0.60; 'dear': 0.63; 'appreciation': 0.67; 'convey': 0.84; 'filename:': 0.84; '169': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=MLRZWBoM3HAAT4et/pgz3CNAKOkE+03aOMdGFiJkZ7k=; b=pZ7vxMGctloUTp05l65w8VH8srrE0do5j1SWMbIlR7ekGm6+dXNA/UKwYxPoO67MQ1 rXPHTsvE4O+qjgmmqiJlm/C0BhQkUSfy0XY/Z0p43qXw5B0ye1iO+mo0fpthWiilonnV 22JkI/4vhWfV39SolmulOOYelUpk6dcT/baEE=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=wRctiFsJVpG5f9u3xxXCAdZY5G9XI9RwfTHk3+9aYYJTAVwizGNEYzz9QxId48YpPh /r6vkpwzCSdbpoAuf0r3gfQJ09+FTKvP+SLeM5eUhAc4NCoGPAoYU41PCwsXajeQZMay BNK2K4f4E6yAS7Pabya87pwK70Y1f4M5cDwas=
MIME-Version 1.0
Date Sat, 18 Jun 2011 18:21:55 -0500
Subject NEED HELP-process words in a text file
From Cathy James <nambo4jb@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.133.1308439317.1164.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 82.94.164.166
X-Trace 1308439317 news.xs4all.nl 49045 [::ffff:82.94.164.166]:34295
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7930

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web