[Tutor] Simple counter to determine frequencies of words in a document

col speed ajarncolin at gmail.com
Sun Nov 21 00:50:19 CET 2010


--> snip

>However, even with countWords2, which is supposed to overcome this
>problem, it feels as if I've entered an infinite loop.

>Josep M.


Just my twopenneth, I'm a noob and I'm not going to try such a big file on
my old machine, but:

1. Maybe create a *set* from the wordlist, loop through that, so you call
"count" on wordlist only once.  OR

2. Use collections.defaultdict(int) and loop through wordlist and do
dic[word] += 1

Maybe, possibly.

Regards
Colin
-- 
if not ErrorMessage:
    check_all()
>>>check_all.__doc__
" noErrorMessage != correctAnswer"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101121/5c850be0/attachment.html>


More information about the Tutor mailing list