def test_word_acceptable(): assert (word_acceptable("dog")) assert not (word_acceptable("C3PO")) # These tests check that I'm using the word list that I expect -- # not that there'd be anything terribly wrong with using some # other list, but I compare the different implementations of this # program based on the time they take to run, and that time is # greatly affected by the choice of word list ... so I use the # same word list for each implementation. d = snarf_dictionary(os.path.join(default_dict_name)) assert (66965 == len(d)) assert (72794 == sum(len(words) for words in d.values()))
dict_as_list = dict_as_list[1:] return rv if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-d", "--dictionary", default=dict.default_dict_name, metavar="FILE", help="location of word list") parser.add_argument('input', nargs='+') args = parser.parse_args() dict_hash_table = dict.snarf_dictionary(args.dictionary) the_phrase = ' '.join(args.input) the_input_bag = Bag(the_phrase) _p("Pruning dictionary. Before:", functools.reduce(lambda acc, elt: acc + len(dict_hash_table[elt]), dict_hash_table, 0), "words ...") # 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
parser.add_option("-d", "--dictionary", action="store", type="string", dest="dict_fn", default=dict.default_dict_name, metavar="FILE", help="location of word list") (options, args) = parser.parse_args() if (0 == len(args)): parser.print_help () sys.exit (0) dict_hash_table = dict.snarf_dictionary (options.dict_fn) the_phrase = bag (args[0]) print >> sys.stderr, "Pruning dictionary. Before:", len (dict_hash_table.keys ()), "bags ...", # 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 = [[k, dict_hash_table[k]] for k in dict_hash_table.keys () if (subtract_bags (the_phrase, k))]
parser.add_option("-d", "--dictionary", action="store", type="string", dest="dict_fn", default="../words.utf8", metavar="FILE", help="location of word list") (options, args) = parser.parse_args() if (0 == len(args)): parser.print_help() sys.exit(0) dict_hash_table = snarf_dictionary(options.dict_fn) the_phrase = bag(args[0]) print "Pruning dictionary. Before:", len( dict_hash_table.keys()), "bags ...", # 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 = [[k, dict_hash_table[k]] for k in dict_hash_table.keys() if (subtract_bags(the_phrase, k))]
return rv if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-d", "--dictionary", default=dict.default_dict_name, metavar="FILE", help="location of word list") parser.add_argument('input', nargs='+') args = parser.parse_args() dict_hash_table = dict.snarf_dictionary(args.dictionary) the_phrase = ' '.join(args.input) the_input_bag = Bag(the_phrase) _p( "Pruning dictionary. Before:", functools.reduce(lambda acc, elt: acc + len(dict_hash_table[elt]), dict_hash_table, 0), "words ...") # 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.