Skip to content

Instantly share code, notes, and snippets.

@anuvrat
Created March 5, 2017 06:46
Show Gist options
  • Save anuvrat/e027dfb7e81647f170ea0b907ec850e0 to your computer and use it in GitHub Desktop.
Save anuvrat/e027dfb7e81647f170ea0b907ec850e0 to your computer and use it in GitHub Desktop.
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