From f549b4aa1ee00c0ff94ce4112a22b7f864f43a4a Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Thu, 10 Dec 2015 10:12:55 +0100 Subject: [PATCH] add word hint generator script --- scripts/dictionary_to_word_hints.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 scripts/dictionary_to_word_hints.py diff --git a/scripts/dictionary_to_word_hints.py b/scripts/dictionary_to_word_hints.py new file mode 100644 index 000000000..761baa4d5 --- /dev/null +++ b/scripts/dictionary_to_word_hints.py @@ -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() +