def get_removed_letters_words2(): words = ch10_ex.load_words() words_dict = ch11_ex.dict_from_list(words) removed_letters_words = [] # words = ["abcd", "sprite"] for word in words: # print(word) for n in range(1, len(word)): # print(n) removal_idices_combinations = get_n_chars_removal_combinations_idices( word, n) any_combination_is_word = False for removal_idices_combination in removal_idices_combinations: # print(removal_idices_combination) removed_letters_word = get_word_after_index_char_removal( word, removal_idices_combination) # print(removed_letters_word) if removed_letters_word in words_dict: # print("in!!!") any_combination_is_word = True # print("!!!", any_combination_is_word) if not any_combination_is_word: break # print("end", any_combination_is_word) if any_combination_is_word: removed_letters_words.append(word) return sorted(removed_letters_words, key=lambda val: len(val), reverse=True)
def get_strange_words(filepath): words_list = ch10_ex.load_words() words_dict = ch11_ex.dict_from_list(words_list) book_words = load_words(filepath) strange_list = [] for word in book_words: if word not in words_dict: strange_list.append(word) print(set(strange_list))
def find_anagram_lists(): words = ch10_ex.load_words() anagrams_sets = defaultdict(list) for word in words: key = tuple(sorted(list(word))) anagrams_sets[key].append(word) return sorted([val for key, val in anagrams_sets.items() if len(val) > 1], key=lambda val: len(val), reverse=True) # !!
def get_all_rotate_pairs(): rotate_pairs = [] words = ch10_ex.load_words() words_dict = dict_from_list(words) for word in words_dict: word_rotations = generate_all_rotations(word) for word_rotation in word_rotations: if word_rotation in words_dict: rotate_pairs.append((word, word_rotation)) return rotate_pairs
def find_metathesis_pairs(): words = ch10_ex.load_words() words_dict = ch11_ex.dict_from_list(words) metathesis_pairs = [] for word in words: swaps = generate_all_characters_swaps(word) for swap in swaps: if swap in words_dict: metathesis_pairs.append((word, swap)) return metathesis_pairs
def get_all_words_correct_word_strippings(): words = ch10_ex.load_words() words_dict = ch11_ex.dict_from_list(words) all_words_stripping_patterns = [] for word in words: print(word) all_correct_word_strippings = get_all_correct_word_strippings( word, words_dict) if len(all_correct_word_strippings) > 0: all_words_stripping_patterns.extend(all_correct_word_strippings) return all_words_stripping_patterns
def look_for_word_homophones(): words = ch10_ex.load_words() words_dict = dict_from_list(words) words_pronounciation_dict = generate_pronounciation_dict() for word in words: word_no_first_letter = word[1:] word_no_second_letter = word[0] + word[2:] if word_no_first_letter not in words_dict or word_no_second_letter not in words_dict: continue if word not in words_pronounciation_dict or word_no_first_letter not in words_pronounciation_dict or word_no_second_letter not in words_pronounciation_dict: continue if words_pronounciation_dict[word] == words_pronounciation_dict[ word_no_first_letter] == words_pronounciation_dict[ word_no_second_letter]: print(word, word_no_first_letter, word_no_second_letter)
def get_strange_words_set(filepath): words_list = ch10_ex.load_words() book_words = load_words(filepath) return subtract(book_words, words_list)