Last active
January 14, 2022 11:22
-
-
Save knudmoeller/de4d1e0753e36f05a464283e3fd6b218 to your computer and use it in GitHub Desktop.
Wordle Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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