1 | ## Morgan Ames
|
2 | ## craft 3
|
3 | ##
|
4 | ## PARTNER'S FUNCTIONS:
|
5 |
|
6 | ## THIS IS THE ONLY FUNCTION I USED
|
7 | def text(w):
|
8 | """determines if the whole text is spelled correctly. uses word(w)."""
|
9 | return w
|
10 |
|
11 |
|
12 | ## PART 2
|
13 | ## Questions for partner:
|
14 | # What does text(w) take as an argument? I'm assuming a LIST.
|
15 | # What do these functions return? Do they modify anything?:
|
16 | # - text (DON'T KNOW; going to say a list of misspelled words.
|
17 | # Could also be list of indices of misspelled words, or ...
|
18 | # I'll assume, since you said "determines if the whole text is
|
19 | # spelled correctly", that it somehow returns all the misspelled
|
20 | # words in a list.)
|
21 | # - word (I assume a boolean)
|
22 | # - dictionary (a file? list? etc.)
|
23 | # - remove (does it return the word? false if it doesn't exist?)
|
24 | # Does word determine whether its argument is a
|
25 | # CORRECTLY-SPELLED word? :~)
|
26 | #
|
27 | ##
|
28 |
|
29 |
|
30 | def file(filename="input.txt"):
|
31 |
|
32 | ## ADD THIS WHEN ACTUALLY USING SPELING.PY MODULE
|
33 | # import speling
|
34 |
|
35 | input_file = open(filename)
|
36 | input_string = input_file.read()
|
37 |
|
38 | stripped_words = map(remove_punc, input_string.split())
|
39 |
|
40 | ## ADD THIS WHEN ACTUALLY USING SPELING.PY MODULE
|
41 | # misspelled_words = speling.text(stripped_words)
|
42 | ## REMOVE THIS WHEN ACTUALLY USING SPELING.PY MODULE
|
43 | misspelled_words = text(stripped_words)
|
44 |
|
45 | misspelled_words.sort()
|
46 |
|
47 | counted_words = []
|
48 | current_word = misspelled_words[0]
|
49 | count = 1
|
50 | for word in misspelled_words[1:]:
|
51 | if word == current_word:
|
52 | count = count + 1
|
53 | else:
|
54 | counted_words.append(current_word + ' (' + str(count) + ')')
|
55 | current_word = word
|
56 | count = 1
|
57 | counted_words.append(current_word + ' (' + str(count) + ')')
|
58 | print '\n'.join(counted_words)
|
59 |
|
60 |
|
61 | def remove_punc(word):
|
62 | if word.isalpha():
|
63 | return word
|
64 | else:
|
65 | stripped_word = ''
|
66 | for char in word:
|
67 | if char.isalpha() or char == "'":
|
68 | stripped_word = stripped_word + char
|
69 | return stripped_word |