Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7938 > unrolled thread
| Started by | Dave Angel <davea@ieee.org> |
|---|---|
| First post | 2011-06-18 22:05 -0400 |
| Last post | 2011-06-18 22:05 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NEED HELP-process words in a text file Dave Angel <davea@ieee.org> - 2011-06-18 22:05 -0400
| From | Dave Angel <davea@ieee.org> |
|---|---|
| Date | 2011-06-18 22:05 -0400 |
| Subject | Re: NEED HELP-process words in a text file |
| Message-ID | <mailman.139.1308449472.1164.python-list@python.org> |
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
Back to top | Article view | comp.lang.python
csiph-web