From be92fc4d6d9ce808c00762b6cb5d33b5de1b3842 Mon Sep 17 00:00:00 2001 From: Crista Lopes Date: Sun, 26 Jan 2014 08:55:25 -0800 Subject: [PATCH] Shorten this a little to fit in 1 page --- 08-kick-your-teammate-forward/tf-08.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/08-kick-your-teammate-forward/tf-08.py b/08-kick-your-teammate-forward/tf-08.py index 3d4406d..354d0d4 100755 --- a/08-kick-your-teammate-forward/tf-08.py +++ b/08-kick-your-teammate-forward/tf-08.py @@ -33,21 +33,16 @@ def frequencies(word_list, func): wf[w] += 1 else: wf[w] = 1 - func(wf, format_text) + func(wf, print_text) 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): - text = "" +def print_text(word_freqs, func): for (w, c) in word_freqs[0:25]: - text = text + w + ' - ' + str(c) + '\n' - func(text, no_op) + print w, "-", c + func(None) -def print_all(text, func): - print text - func(None) - def no_op(func): return