From dbc3d16f6598037f73945fd8b11c24a4274c9ae0 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 3 May 2014 20:54:12 -0500 Subject: [PATCH] Markov: only add sentence punctuation if necessary --- markov/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markov/views.py b/markov/views.py index ea7bd37..a5a5690 100644 --- a/markov/views.py +++ b/markov/views.py @@ -158,7 +158,8 @@ def _generate_line(context, topics=None, min_words=15, max_words=30): if len(line) >= min_words: return line else: - line[-1] += random.choice([',', '.', '!']) + if line[-1][-1] not in [',', '.', '!']: + line[-1] += random.choice([',', '.', '!']) tries += 1