import os from collections import Counter from play import MOVE_SEP, BLANK def main(): hint = input("hint >") no_letters = input('no >') hint = hint.lower().replace(' ', '') regex = '' for char in hint: regex += '[{}]'.format(char) regex = regex.replace('[_]', '[[:alpha:]]') command = "grep -Ei '^{}$' /usr/share/dict/bulgarian".format(regex) if no_letters: command += " | grep -Eiv '{}'".format('|'.join(no_letters)) print(MOVE_SEP) print(command) print(MOVE_SEP) words = os.popen(command).read().split('\n')[:-1] print("{} words".format(len(words))) print(MOVE_SEP) characters = Counter() for word in words: word = word.lower() word_chars = set(word) characters += Counter(list(word_chars)) for char in hint: if char not in [BLANK]: del characters[char] if len(words) < 100: for word in words: print(word) print(MOVE_SEP) print(characters.most_common()) if __name__ == '__main__': main()