File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,13 @@ def nth_order_markov(order, text_list):
6565def start_token (dictionary ):
6666 """ Get words that can start a sentence; this method is O(n) worst case
6767 because one must check every word in the corpus"""
68- start_tokens = []
69- for key in dictionary :
70- if key [0 ].islower () is False and key [0 ].endswith ('.' ) is False :
71- start_tokens .append (key )
68+ # rewritten with dict comprehension
69+ start_tokens = [key for key in dictionary if key [0 ].islower () is False and key [0 ].endswith ('.' ) is False ]
70+
71+ # for key in dictionary:
72+ # if key[0].islower() is False and key[0].endswith('.') is False:
73+ # start_tokens.append(key)
74+
7275 token = random .choice (start_tokens )
7376 return token
7477
@@ -127,7 +130,6 @@ def main(text_list):
127130 end_words = stop_token (dictionary )
128131 markov_list = create_sentence (first_word , end_words , dictionary )
129132 markov_sentence = " " .join (markov_list )
130- # print(markov_sentence)
131133 return markov_sentence
132134
133135if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments