Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'pm,': 0.10; '>>>': 0.12; 'def': 0.12; 'skip:f 30': 0.14; 'subject:file': 0.14; 'wrote:': 0.14; 'computes': 0.16; 'encountered.': 0.16; 'filename,': 0.16; 'lengths': 0.16; 'newborn': 0.16; 'printing.': 0.16; 'argument': 0.16; 'cc:addr:python-list': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'do,': 0.25; 'function': 0.25; 'string': 0.26; 'script': 0.27; 'bugs': 0.29; 'import': 0.29; "python's": 0.29; 'subject:HELP': 0.29; 'cc:addr:python.org': 0.30; 'separated': 0.30; 'it.': 0.31; 'print': 0.31; 'word.': 0.32; 'words,': 0.32; 'does': 0.33; 'skip:" 20': 0.33; 'showing': 0.34; 'header:User-Agent:1': 0.35; 'function.': 0.35; 'subject:text': 0.36; 'several': 0.36; 'table': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'skip:s 20': 0.39; 'should': 0.39; "i'd": 0.39; 'current': 0.40; 'help': 0.40; 'received:192.168.1': 0.40; 'your': 0.60; 'dear': 0.63; 'appreciation': 0.67; 'nothing.': 0.67; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; '02:59': 0.84; 'convey': 0.84; 'filename:': 0.84; 'irrelevant.': 0.84; '169': 0.91 Date: Sat, 18 Jun 2011 22:05:55 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 MIME-Version: 1.0 To: Cathy James Subject: Re: NEED HELP-process words in a text file References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:5FRCk7gzN0tFtB9qIbHn7wEKXIqqYTViYI4EMD4sZy3 EQsZ03OeO6jOZjK42igv/YwJfTdTJxzqLOaN6/VjEs46H4D7Tz InPWIXuGk9VWeZrl0Y3B8b99N+TkFKHYq/IDTSIxPSQv3vVWyU OWro6MvnFor3ZkqJjoCJoix78CPx9JhgIv01TqHzrVBwuBYZir r21HLtxTDHVNpDMci1/Pw== Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: davea@ieee.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 60 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308449473 news.xs4all.nl 49179 [::ffff:82.94.164.166]:60254 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7938 On 01/-10/-28163 02:59 PM, Cathy James wrote: > 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. > You create a function fileProcess() with several bugs in it. But you never call it, so the bugs are irrelevant. The script does precisely nothing. DaveA