rv.extend(combine(words, from_smaller_bag)) return rv if __name__ == "__main__": parser = parser = argparse.ArgumentParser() parser.add_argument('words', nargs='+') parser.add_argument('--dictionary', default=dict.default_dict_name, help="location of word list") args = parser.parse_args() dict_hash_table = dict.snarf_dictionary_from_file(args.dictionary) the_phrase = Bag(''.join(args.words)) print("Pruning dictionary. Before: {} bags ...".format( len(dict_hash_table.keys())), file=sys.stderr, end='') # Now convert the hash table to a list, longest entries first. (This # isn't necessary, but it makes the more interesting anagrams appear # first.) # While we're at it, prune the list, too. That _is_ necessary for the # program to finish before you grow old and die. the_dict_list = sorted(
def test_proper_word_filtering(self): d = snarf_dictionary_from_file(os.path.join(default_dict_name)) self.assertEqual(66965, len(d)) self.assertEqual(72794, sum(len(words) for words in d.values()))
if not from_smaller_bag: continue rv.extend(combine(words, from_smaller_bag)) return rv if __name__ == "__main__": parser = parser = argparse.ArgumentParser() parser.add_argument("words", nargs="+") parser.add_argument("--dictionary", default=dict.default_dict_name, help="location of word list") args = parser.parse_args() dict_hash_table = dict.snarf_dictionary_from_file(args.dictionary) the_phrase = Bag("".join(args.words)) print("Pruning dictionary. Before: {} bags ...".format(len(dict_hash_table.keys())), file=sys.stderr, end="") # Now convert the hash table to a list, longest entries first. (This # isn't necessary, but it makes the more interesting anagrams appear # first.) # While we're at it, prune the list, too. That _is_ necessary for the # program to finish before you grow old and die. the_dict_list = sorted([[k, dict_hash_table[k]] for k in dict_hash_table.keys() if the_phrase.subtract(k)], key=len) print(" After: {} bags.".format(len(the_dict_list)), file=sys.stderr)