Update lettercount.py
This commit is contained in:
@@ -73,15 +73,17 @@ def convert_files(filenames, mincount=1e5):
|
|||||||
write_dict(D, 'WORD-' + f[-1].upper())
|
write_dict(D, 'WORD-' + f[-1].upper())
|
||||||
report(f, D, 'popular')
|
report(f, D, 'popular')
|
||||||
|
|
||||||
def load():
|
def load(filename='top-words.txt'):
|
||||||
|
"Load file of 'word \t count' lines into D (a dict), W (length of D) and M (total number of words)."
|
||||||
global D, W, M
|
global D, W, M
|
||||||
D = read_dict('top-words.txt')
|
D = read_dict(filename)
|
||||||
W = len(D)
|
W = len(D)
|
||||||
M = sum(D.values())
|
M = sum(D.values())
|
||||||
|
|
||||||
#### Compute letter counts and save as HTML files.
|
#### Compute letter counts and save as HTML files.
|
||||||
|
|
||||||
def histogram(items):
|
def histogram(items):
|
||||||
|
"Return a Counter of the number of times each key occurs in (key, val) pairs."
|
||||||
C = Counter()
|
C = Counter()
|
||||||
for (key, val) in items:
|
for (key, val) in items:
|
||||||
C[key] += val
|
C[key] += val
|
||||||
|
|||||||
Reference in New Issue
Block a user