Skip to content

Instantly share code, notes, and snippets.

@slackorama

slackorama/panagram.py

Last active Jan 13, 2021
Embed
What would you like to do?
Solve the NYT spelling bee. Mind you this isn't perfect.
#!/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