Skip to content

Instantly share code, notes, and snippets.

@knudmoeller
Last active January 14, 2022 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knudmoeller/de4d1e0753e36f05a464283e3fd6b218 to your computer and use it in GitHub Desktop.
Save knudmoeller/de4d1e0753e36f05a464283e3fd6b218 to your computer and use it in GitHub Desktop.
Wordle Filter
import subprocess
# read the dictionary file:
result = subprocess.run(['egrep', '^.{5}$', "/usr/share/dict/words"], stdout=subprocess.PIPE)
words = result.stdout.decode('utf-8').splitlines()
present = ['a', 'n', 'g', 't'] # letters that we know are in the word
not_present = ['o', 'i', 's', 'e', 'u'] # letters we know are not in the word
# filter words with all() and not any()
candidates = [word for word in words if
all([letter in word for letter in present]) and
not any([letter in word for letter in not_present])
]
print(candidates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment