## Morgan Ames ## craft 3 ## ## PARTNER'S FUNCTIONS: ## THIS IS THE ONLY FUNCTION I USED def text(w): """determines if the whole text is spelled correctly. uses word(w).""" return w ## PART 2 ## Questions for partner: # What does text(w) take as an argument? I'm assuming a LIST. # What do these functions return? Do they modify anything?: # - text (DON'T KNOW; going to say a list of misspelled words. # Could also be list of indices of misspelled words, or ... # I'll assume, since you said "determines if the whole text is # spelled correctly", that it somehow returns all the misspelled # words in a list.) # - word (I assume a boolean) # - dictionary (a file? list? etc.) # - remove (does it return the word? false if it doesn't exist?) # Does word determine whether its argument is a # CORRECTLY-SPELLED word? :~) # ## def file(filename="input.txt"): ## ADD THIS WHEN ACTUALLY USING SPELING.PY MODULE # import speling input_file = open(filename) input_string = input_file.read() stripped_words = map(remove_punc, input_string.split()) ## ADD THIS WHEN ACTUALLY USING SPELING.PY MODULE # misspelled_words = speling.text(stripped_words) ## REMOVE THIS WHEN ACTUALLY USING SPELING.PY MODULE misspelled_words = text(stripped_words) misspelled_words.sort() counted_words = [] current_word = misspelled_words[0] count = 1 for word in misspelled_words[1:]: if word == current_word: count = count + 1 else: counted_words.append(current_word + ' (' + str(count) + ')') current_word = word count = 1 counted_words.append(current_word + ' (' + str(count) + ')') print '\n'.join(counted_words) def remove_punc(word): if word.isalpha(): return word else: stripped_word = '' for char in word: if char.isalpha() or char == "'": stripped_word = stripped_word + char return stripped_word