From 20b925d9544bb180dd05e1850290b40b16dec9d6 Mon Sep 17 00:00:00 2001 From: Crista Lopes Date: Thu, 7 Nov 2013 16:43:35 -0800 Subject: [PATCH] I'm liking loops in Forth. --- 02-go-forth/tf-02.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/02-go-forth/tf-02.py b/02-go-forth/tf-02.py index 1466252..17b8e93 100755 --- a/02-go-forth/tf-02.py +++ b/02-go-forth/tf-02.py @@ -102,7 +102,10 @@ stack.append(sys.argv[1]) read_file(); filter_chars(); scan(); remove_stop_words() frequencies(); sort() -for i in range(0, 25): - (w, f) = stack.pop() - print w, ' - ', f +stack.append(0) +while stack[-1] < 25: + heap['i'] = stack.pop() + (w, f) = stack.pop(); print w, ' - ', f + stack.append(heap['i']); stack.append(1) + stack.append(stack.pop() + stack.pop())