-
-
Save anuvrat/e027dfb7e81647f170ea0b907ec850e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _get_next_words(self, word): | |
if word not in self.next_words_dict: | |
self._generate_next_words_list(word) | |
return self.next_words_dict[word] | |
def _generate_next_words_list(self, word): | |
next_words = [] | |
word_array = list(word) | |
for i in range(len(word_array)): | |
old_c = word_array[i] | |
for c in ascii_lowercase: | |
if not c == old_c: | |
word_array[i] = c | |
new_word = ''.join(word_array) | |
if new_word not in self.word_levels and new_word in self.words_map: | |
next_words.append(new_word) | |
word_array[i] = old_c | |
self.next_words_dict[word] = next_words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment