diff --git a/02-go-forth/tf-02.py b/02-go-forth/tf-02.py index 1e50c35..235f467 100755 --- a/02-go-forth/tf-02.py +++ b/02-go-forth/tf-02.py @@ -101,7 +101,9 @@ read_file(); filter_chars(); scan(); remove_stop_words() frequencies(); sort() stack.append(0) -while stack[-1] < 25: +# Check stack length against 1, because after we process +# the last word there will be one item left +while stack[-1] < 25 and len(stack) > 1: heap['i'] = stack.pop() (w, f) = stack.pop(); print w, ' - ', f stack.append(heap['i']); stack.append(1)