You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
988 B

#!/usr/bin/python
import re
import itertools
from spellchecker import SpellChecker
SPELL= SpellChecker()
def canidates(letters, min=2, max=5):
pos = []
for length in range(min, max+1):
for comb in itertools.combinations(letters, length):
for perm in itertools.permutations(comb):
word = ''.join(perm)
pos.append(word)
return SPELL.known(pos)
def filter_pos(pos, regex):
pat = re.compile(regex + '$')
return list(filter(pat.match,pos))
while True:
letters = input('Enter letters: ')
if letters == ":quit:":
break
pos = canidates(letters)
inp = None
while inp not in (":quit:",":new:"):
if inp is not None:
for word in filter_pos(pos, inp):
print('>>>',word)
print('Letters: ',','.join(letters))
prompt = "Enter pattern, ':new:' for new letters,\nor ':quit:' to exit: "
inp = input(prompt)
if inp == ":quit:":
break