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.

30 lines
888 B

  1. #!/usr/bin/python
  2. import re
  3. import itertools
  4. from spellchecker import SpellChecker
  5. SPELL= SpellChecker()
  6. def canidates(letters, min=2, max=5):
  7. pos = []
  8. for length in range(min, max+1):
  9. for comb in itertools.combinations(letters, length):
  10. for perm in itertools.permutations(comb):
  11. word = ''.join(perm)
  12. pos.append(word)
  13. return SPELL.known(pos)
  14. def filter_pos(pos, regex):
  15. pat = re.compile(regex)
  16. return list(filter(pat.match,pos))
  17. while True:
  18. letters = input('Enter letters: ')
  19. pos = canidates(letters)
  20. inp = None
  21. while inp not in (":quit:",":new:"):
  22. if inp is not None:
  23. for word in filter_pos(pos, inp):
  24. print(word)
  25. prompt = "Enter pattern, ':new:' for new letters, or ':quit:' to exit: "
  26. inp = input(prompt)
  27. if inp == ":quit:":
  28. break