Add a check to handle input text with fewer than 25 words.

This commit is contained in:
smtriplett
2014-01-11 18:19:32 -08:00
parent ebff0a19b6
commit 4d3ba0ba1a

View File

@@ -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)