Shorten this a little to fit in 1 page
This commit is contained in:
@@ -33,21 +33,16 @@ def frequencies(word_list, func):
|
|||||||
wf[w] += 1
|
wf[w] += 1
|
||||||
else:
|
else:
|
||||||
wf[w] = 1
|
wf[w] = 1
|
||||||
func(wf, format_text)
|
func(wf, print_text)
|
||||||
|
|
||||||
def sort(wf, func):
|
def sort(wf, func):
|
||||||
func(sorted(wf.iteritems(), key=operator.itemgetter(1), reverse=True), print_all)
|
func(sorted(wf.iteritems(), key=operator.itemgetter(1), reverse=True), no_op)
|
||||||
|
|
||||||
def format_text(word_freqs, func):
|
def print_text(word_freqs, func):
|
||||||
text = ""
|
|
||||||
for (w, c) in word_freqs[0:25]:
|
for (w, c) in word_freqs[0:25]:
|
||||||
text = text + w + ' - ' + str(c) + '\n'
|
print w, "-", c
|
||||||
func(text, no_op)
|
func(None)
|
||||||
|
|
||||||
def print_all(text, func):
|
|
||||||
print text
|
|
||||||
func(None)
|
|
||||||
|
|
||||||
def no_op(func):
|
def no_op(func):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user