# unscramble.py # Steve Marschner (srm2), Lillian Lee (ljl2) # Mar 3, 2014 """Anagram solver for CS1110 Lab 6. The purpose of this program is to solve anagrams, like the ones that form part of many word games and word puzzles. For instance, given the string "opython" we would like the program to tell us it is an anagram of "typhoon" -- meaning that it contains the same letters, but possibly in a different order. The script is used by running it from the command line with a word or words as arguments. For instance, python unscramble.py opython should produce the output opython is an anagram of typhoon If the user provides several words, the script should attempt to find anagrams for all of them. The input words are converted to lowercase before anagram solving begins. """ import sys def sort_string_letters(s): """Return a copy of s with the characters sorted in alphabetical order. When capital letters are involved, 'sorted' here means that all uppercase letters go before lowercase letters. Ex: 'bcD' -> 'Dbc'. """ # Implementation note: the spec above just means that you can use # Python's regular old sort function, because that's how it handles # capitalization. pass def unscramble(anagram): """Attempts to unscramble an anagram of an English word. If contains a permutation of the letters in an English word, print the word. If not, print an error message. """ #temporary code to help check that Section 2's task is accomplished. print "running unscramble function on " + anagram # The name of a text file containing a list of words, one word per line. DICT_FILE = 'small_dict.txt' # When you are confident that your code is working, uncomment the # DICT_FILE = 'scowl-utf-8.txt' # line below to get access to a "real" dictionary. # We are using a word list from Kevin Atkinson's SCOWL (Spell Checker # Oriented Word Lists) project, see wordlist.sourceforge.net. # # TODO: uncomment this line when ready! # DICT_FILE = 'scowl_utf-8.txt' # TODO: fix/replace these stubbed-in assignment statements dictionary = [] rep_dict = [] if __name__ == '__main__': # This is temporary code to help you understand how for-loops can be # applied to the list of command-line arguments. # TODO: replace with different code as stated in handout print 'sys.argv is: ' + str(sys.argv) for item in sys.argv: print item print ' length of ' + item + ' is ' + str(len(item)) # Temporary code: command that prints out usage message to demonstrate # what a usage message should look like print "Usage: python unscramble.py [...]"