def main(): name = 'tmvoordle'.lower() word_list_ini = load('words.txt') trigrams_filtered = load('least-likely_trigrams.txt') word_list = prep_words(name, word_list_ini) filtered_cv_map = cv_map_words(word_list) filter_1 = cv_map_filter(name, filtered_cv_map) filter_2 = trigram_filter(filter_1, trigrams_filtered) filter_3 = letter_pair_filter(filter_2) view_by_letter(name, filter_3)
def main(): word_list = load('words.txt') stop_program_command = 'q' while True: user_word = input( f"Provide a word or type '{stop_program_command}' to finish: ") if user_word == stop_program_command: break anagrams = get_word_anagrams_from_words_list(user_word, word_list) print(anagrams)
def main(): dictionary = load("words.txt") word = 'tmvoordle'.lower() word_perms = {''.join(perm) for perm in permutations(word, 2)} perms_counter = Counter() for entry in dictionary: entry = entry.lower() if len(entry) <= 1: continue for word_perm in word_perms: perms_counter[word_perm] += entry.count(word_perm) print(perms_counter)
"""Generate letter pairs in Voldemort & find their frequency in a dictionary. Requires load_dictionary.py module to load an English dictionary file. """ import re from collections import defaultdict from itertools import permutations from Chapter_3 import load_dictionary word_list = load_dictionary.load('words.txt') name = 'Voldemort' #(tmvoordle) name = name.lower() # generate unique letter pairs from name digrams = set() perms = {''.join(i) for i in permutations(name)} for perm in perms: for i in range(0, len(perm) - 1): digrams.add(perm[i] + perm[i + 1]) print(*digrams, sep='\n') print("\nNumber of digrams = {}\n".format(len(digrams))) # use regular expressions to find repeating digrams in a word mapped = defaultdict(int) for word in word_list: word = word.lower() for digram in digrams: for m in re.finditer(digram, word): mapped[digram] += 1
from collections import Counter from itertools import permutations from Chapter_3.load_dictionary import load robert_dict_file = load('words.txt') robert_dict_file = set(robert_dict_file) solutionsd = set() def is_word_valid(perm): return "".join(perm) in robert_dict_file def my_perm3(current_words, remaining_letters): global solutionsd remaining_letters_len = sum(remaining_letters.values()) if remaining_letters_len == 0: # print("current_words:", current_words) solutionsd.add(tuple(current_words)) # elif remaining_letters_len < 2: # return for sub_len in range(remaining_letters_len, 1, -1): perms = permutations(remaining_letters, sub_len) for perm in perms: if not is_word_valid(perm): continue rem = (Counter(remaining_letters) - Counter(perm)) # print('perm:', perm) # print('rem:', rem) my_perm3(current_words + [''.join(perm)], rem)
from collections import Counter import sys from Chapter_3.load_dictionary import load dict_file = load('words.txt') def find_anagrams(name, word_list): """Read name and dictionary file and display all anagrams IN name.""" name_letter_map = Counter(name) anagrams = [] for word in word_list: test = '' word_letter_map = Counter(word.lower()) for letter in word: if word_letter_map[letter] <= name_letter_map[letter]: test += letter if Counter(test) == word_letter_map: anagrams.append(word) print(*anagrams, sep='\n') print() print(f"Remaining letter = {name}") print(f"Number of remaining letters = {len(name)}") print(f"Number of remaining (real word) anagrams = {len(anagrams)}") return anagrams def process_choice(name): """Check user choice for validity, return choice and leftover letters.""" while True: