# solvejumble.py # this kind of signature is just the letters of a word # in alphabetical order def signature(word): chars = list(word) chars.sort() return chars # This creates and returns a (potentially really long) list of all the # words in the given file. def wordlist(fname): with open(fname) as f: return f.read().split() # This goes through every word in the dictionary and checks to # see if it has the same signature as the given word. def matches(jumble): sign = signature(jumble) result = [] for word in wordlist("dictionary.txt"): if signature(word) == sign: result.append(word) return result def main(): jumble = input("Enter a scrambled word: ") print("Matches are:", matches(jumble)) main()