def solve(jumbles, dict): """Takes the solved individual jumbles and solves the punchline""" freq = pickle.load(file("word_frequency.pickle")) jumble = Jumble() agrams = [] # Isolate the important letters from the solved jumbles for j in jumbles: jumble.agrams = [] for ana in j.agrams: for pos in j.positions: jumble.original += ana[pos] # Find anagrams of the final character set try: jumble.agrams += findWord(jumble.original, dict) print jumble.agrams except: pass
def main(): dictFile = file("words.pickle") dict = pickle.load(dictFile) jumbles = [] i = 0 while 1: # Get jumbles from the user and process them j = Jumble() j.original = raw_input("Next jumbled word: ") if j.original == "": break positions = raw_input("Important positions in this word: ") j.positions = positions.split(",") for i in range(0, len(j.positions)): j.positions[i] = int(j.positions[i]) j.positions[i] = j.positions[i] - 1 j.agrams = findWord(j.original, dict) jumbles.append(j) i += 1 solve(jumbles, dict)