From 3ace25b6e2bacb741d9be9b6d6dd829ea2f8779f Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Sun, 14 Aug 2016 17:43:03 -0400 Subject: [PATCH] Try and fix occasional exception --- generate_poem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generate_poem.py b/generate_poem.py index 62935d0..f724327 100644 --- a/generate_poem.py +++ b/generate_poem.py @@ -103,10 +103,14 @@ class PoemGenerator(): haiku = haiku + ' '.join(first) + '\n' next_words = [freq[0] for freq in self.cfd[first[-1]].items() if not self.only_punctuation.match(freq[0])] + if not next_words: + next_words = self.all_words second = self.haiku_line([], 0, next_words, 7) haiku = haiku + ' '.join(second) + '\n' next_words = [freq[0] for freq in self.cfd[second[-1]].items() if not self.only_punctuation.match(freq[0])] + if not next_words: + next_words = self.all_words third = self.haiku_line([], 0, next_words, 5) haiku = haiku + ' '.join(third) + '\n' return haiku