# CS 1210, Fall 2021, Discussion assignment 4 # DISCUSSION SECTION WORK: # # 1. STUDENTS: Download two files from the "Discussion section assignments" section # of the course website: # - this file, ds4.py # - wordsMany.txt (this is the same as the one used for DS3) # Save both in the same folder. # # 2. TA (aloud) and STUDENTS: Read the comments from START HERE! (just after these instructions) # to definition of wordInfo function. Discuss any questions about what the functions should do. # # 3. TA demonstrate running wordInfo("wordsMany.txt", "anagrams") on this unchanged file, to # see that it behaves reasonably despite having incomplete anagram/neighbor-testing functions. # STUDENTS should do the same on their computers. # Try regular words ("cat", etc.) and non-words (e.g. "abcd"). Quit via Enter/Return. # # 4. STUDENTS: Implement areAnagrams, and test it directly. # E.g. test via areAnagrams("cat", "act"), areAnagrams("bull", "bulb"), etc. # # BIG HINT (TA DISCUSS THIS HINT IF HELPFUL): # How can we test if two words are anagrams? # Type to a Python shell: sorted("cat") and then sorted("act") # From what you see, you should get an idea of how to # implement areAnagrams very easily. # # 5. STUDENTS: Implement getAnagramsOf and test it. There is a hint in getAnagramsOf stub below. # # 6. Now try wordInfo("wordsMany.txt", "anagrams") again. # Try on whatever words you want. Some suggestions: art, stop, spear, least # # 7. Like steps 4, 5, and 6, implement areNeighbors and getNeighborsOf, and then # try wordInfo("wordsMany.txt", "neighbors") # Hint: getNeighborsOf will be exactly the same as getAnagramsOf except for one function call. # # SUBMIT THIS WHOLE FILE ON ICON. # ####### START HERE! (AFTER READING INSTRUCTIONS ABOVE) ########## # # DEFINITIONS: # anagrams: two words are anagrams of each other if it is possible to rearrange # the letters to produce the other. For example, "rat" and "art" and "tar" # are anagrams of each other, as are "ropes" and "prose" # Note: it is not enough for the two words just to have the same letters. # E.g., "bull" and "bulb" are *not* anagrams. They both contain b, u, and l but # the bull cannot be rearranged to spell bulb. # # neighbors: two words are neighbors of each other if they are the same # length and their letters are the same at all but one position. I.e. for # equal length strings, string1 and string2, string1[i] != string2[i] for exactly # one value 0<=i