# This problem introduced during lecture has been# partitioned into four related functions.## Programmers Rick Mercer and YOUR NAME#def createList(): # Return a list of all words in 'BoggleWords.txt' allWords = [] # TODO Store all words in the file into the list allWords # Remember to to add rstrip() to remove the end of line character # to every line in the file. Why? Because ""aardvark\n" is not equal # to "aardvark". If you do not use rstrip(), the asserts below # will fail even though assert(wordList[0] will print aardvark. return allWords
wordList = createList()assert(wordList[0] == 'aardvark')assert(wordList[4] == 'abacus')assert(wordList[11469] == 'chemotherapeutic')assert(wordList[81054] == 'zymurgy')######################################################################
def sortedWord(word): # convert 'String!' to '!ginrst' # TODO: Convert word to a 'sorted' version return '!ginrst'
assert(sortedWord('a') == 'a')assert(sortedWord('water') == 'aertw')assert(sortedWord('baby') == 'abby')assert(sortedWord('baby') == 'abby')assert(sortedWord('chemotherapeutic') == 'acceeehhimoprttu')######################################################################
def getAnagrams(word, aList): # return a list of all anagrams of the given word anagrams = [] # TODO: Find all words in aList that are anagrams of word
return anagrams
allWords = createList()search = 'recant'anagrams = getAnagrams(search, allWords)assert(anagrams[0] == 'canter')assert(anagrams[1] == 'nectar')assert(anagrams[2] == 'trance')######################################################################
def main(): # Allow a user to enter as many words as they want print('Enter a word (no spaces) or "zzz" to quit') print() # TODO: Allow the user to enter as many words as they want # to see the list of all anagrams found in Bogglewords.txt
main() # Call the main() function that repeatedly asks for words # TODO: Nothing