Last active
January 13, 2021 02:08
-
-
Save slackorama/f842235329cc99fe4e86593dcd6a1e09 to your computer and use it in GitHub Desktop.
Solve the NYT spelling bee. Mind you this isn't perfect.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import sys | |
# called via `panagram.py ktocail` | |
# last letter in the word is required | |
def get_words(letters): | |
# prevent dupes | |
seen = set() | |
check = set(list(letters)) | |
required = letters[-1] | |
with open('/usr/share/dict/american-english') as f: | |
for line in f: | |
# strip out words with apostrophes | |
word = line.strip().lower().split("'")[0] | |
if len(word) >= 4 and word not in seen: | |
if required in word and set(word).issubset(check): | |
seen.add(word) | |
if check == set(word): | |
print('PANAGRAM ', end='') | |
print(word) | |
if __name__ == '__main__': | |
get_words(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment