add word hint generator script
This commit is contained in:
parent
3be81ba62a
commit
f549b4aa1e
39
scripts/dictionary_to_word_hints.py
Normal file
39
scripts/dictionary_to_word_hints.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
import sys
|
||||||
|
import string
|
||||||
|
|
||||||
|
def filter_hints(words):
|
||||||
|
|
||||||
|
alphabet = set("asdflkjqwerpoiu")
|
||||||
|
hints = set()
|
||||||
|
|
||||||
|
for word in words:
|
||||||
|
|
||||||
|
# hints should be lowercase
|
||||||
|
word = word.lower()
|
||||||
|
|
||||||
|
# hints should be alphabetic
|
||||||
|
if not set(word) <= alphabet:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# hints shouldn't be longer than 5 characters
|
||||||
|
if len(word) > 5:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# hints should not be prefixes of other hints. we prefer the
|
||||||
|
# longer ones.
|
||||||
|
for i in range(len(word)):
|
||||||
|
hints.discard(word[:i+1])
|
||||||
|
|
||||||
|
hints.add(word)
|
||||||
|
|
||||||
|
yield from hints
|
||||||
|
|
||||||
|
def main():
|
||||||
|
inlines = (line.rstrip() for line in sys.stdin)
|
||||||
|
outlines = ("{}\n".format(hint) for hint in filter_hints(inlines))
|
||||||
|
sys.stdout.writelines(outlines)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user