deflist_words_with_count(letters, count): for word in permutations(letters, count): yield''.join(word)
deflist_words_with_pattern(letters, pattern): random_chars = list(letters) random_count = 0 for c in pattern: if c == '*': random_count += 1 else: try: random_chars.remove(c) except ValueError: raise ValueError('Invalid letter in pattern: {}'.format(c))
for chars in permutations(random_chars, random_count): _p = list(pattern) i = 0 for _i, _c in enumerate(_p): if _c == '*': _p[_i] = chars[i] i += 1 yield''.join(_p)
deflist_words(letters, param): if param isNoneor isinstance(param, int): g = list_words_with_count(letters, param) else: g = list_words_with_pattern(letters, param)
d = enchant.Dict('en_US') word_set = {w for w in g if d.check(w)} print('\n'.join(word_set))