cataloging words in text file
grante at visi.com
Fri Mar 2 23:29:47 CET 2001
In article <3AA0124E.74A39783 at comm.mot.com>, Stephen Boulet wrote:
>I remember this homework assignment for my data structures (c++)
>class: read in a large file, and create a data structure containing
>every word in the file and the number of times it appears.
>I was wondering how to do this in python. In c++ we had to do it
>with hash tables and b-trees.
>Can you do it with dictionaries in python, with the key as the word
>and the data the number of times it appears?
for w in sys.stdin.read().split():
d[w] += 1
d[w] = 1
You may want something a little more sophisticated than
split(), since this solution is case sensitive and treats
"foo" and "foo." as two different words.
Grant Edwards grante Yow! .. I don't understand
at the HUMOR of the THREE
More information about the Python-list