# CSE 143, Winter 2010, Marty Stepp # Homework 6 (Anagrams) # # AnagramMain is a client program that prompts a user for the name of a # dictionary file and then gives the user the opportunity to find anagrams of # various phrases. It constructs an Anagrams object to do the actual # search for anagrams that match the user's phrases. # # originally written by Stuart Reges, 5/9/2005 # modified by Marty Stepp, 2/15/2010 from anagrams import * # dictionary file to use for input (change to dict2, dict3) DICTIONARY_FILE = "dict1.txt" # set to true to test runtime and # of letter inventories created TIMING = False print("Welcome to the CSE 143 anagram solver.") print("Using dictionary file " + DICTIONARY_FILE + ".") # read dictionary into a list dictionary = [] for line in open(DICTIONARY_FILE): dictionary.append(line.strip()) # create Anagrams object for, well, solving anagrams solver = Anagrams(dictionary) # get first phrase to solve phrase = input("Phrase to scramble (Enter to quit)? ").strip() # loop to get/solve each phrase while len(phrase) > 0: print("All words found in \"" + phrase + "\":") all_words = solver.words(phrase) print(all_words) print("") max = input("Max words to include (Enter for no max)? ").strip() if len(max) > 0: # use a max max = int(max) solver.print_anagrams(phrase, max) # print all anagrams of phrase else: # no max solver.print_anagrams(phrase) # print all anagrams of phrase print("") phrase = input("Phrase to scramble (Enter to quit)? ").strip()