Add a check to handle input text with fewer than 25 words.
This commit is contained in:
@@ -101,7 +101,9 @@ read_file(); filter_chars(); scan(); remove_stop_words()
|
|||||||
frequencies(); sort()
|
frequencies(); sort()
|
||||||
|
|
||||||
stack.append(0)
|
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()
|
heap['i'] = stack.pop()
|
||||||
(w, f) = stack.pop(); print w, ' - ', f
|
(w, f) = stack.pop(); print w, ' - ', f
|
||||||
stack.append(heap['i']); stack.append(1)
|
stack.append(heap['i']); stack.append(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user