From ed66246f1496e8ed6820ed23bb5f4b80547dba48 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 4 Dec 2016 10:50:02 -0600 Subject: [PATCH] markov: don't append punctuation to nothingness this is an attempt to fix bss/dr.botzo#10 --- dr_botzo/markov/lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dr_botzo/markov/lib.py b/dr_botzo/markov/lib.py index 9198ef4..9e7243a 100644 --- a/dr_botzo/markov/lib.py +++ b/dr_botzo/markov/lib.py @@ -21,8 +21,9 @@ def generate_line(context, topics=None, min_words=15, max_words=30, sentence_bia if len(line) >= min_words: return line else: - if line[-1][-1] not in [',', '.', '!', '?', ':']: - line[-1] += random.choice(['?', '.', '!']) + if len(line) > 0: + if line[-1][-1] not in [',', '.', '!', '?', ':']: + line[-1] += random.choice(['?', '.', '!']) tries += 1