Assignment 3 Part 1 (submitted by Nerissa on Feb 9, 15:20)

Beautiful Code
Ka-Ping Yee

AUTHORS:   Adam   Calvin   Chris   David   Derek   Hunter   Jacob   Jason   Jun   Karl   Kevin   Michael   Morgan   Nadia   Nerissa   Omair   Peter   Peterson   Ping   Richard   Rosie   Scott   Thanh   Varun

Download this file.

COMMENTS

Feb 17, 17:19 - Scott: Sending one line at a time to the module that checks spelling will make locating lines where errors occur easier. It also speads things up as the dictionary need not be loaded as often.

Feb 17, 17:30 - Scott: There is some confusion on opening files. For one the open() command is being used within the parse_file module which leaves it unusable to the rest of the program (in my opinion less desirable). Second 'foo.txt' is what is being opened...although 'input.txt' is the actual file name. Some error handling would be nice too (incase the file is not in the same directory as the program).

Feb 17, 18:22 - Scott (line 12): There is lots of confusion as to the capabilities of the command 'in' in a for loop. in checks for membership in a sequence and cannot distinguish a line in a file.

Feb 17, 18:24 - Scott (line 26): misspell_keys is not defined anywhere before this...I believe this should be keys.

Feb 17, 18:28 - Scott (line 27): repr(misspelled_words_dict.get(k)) can be replaced by misspelled_words_dict[k] ...much more simple...less confusing

Feb 19, 01:08 - Scott: Okay, my bad. for line in file: does work...I'm using Python 1.5 where this is NOT implimented. In the meantime I've wasted days trying to figure how to impliment these few lines.

Please log in if you would like to add comments.

   

  1 import speling
  2 
  3 misspelled_words_dict = {}
  4 
  5 def parse_file(text_file):
  6     """Reads in a text file and returns a list of 'sentences'.
  7 
  8     A 'sentence' is defined to be just a line of text.
  9     """
 10     file = open(text_file)
 11     alist = []
 12     for line in file:
 13         alist.append(line)
 14     return alist
 15 
 16 sentence_list = parse_file('foo.txt')
 17 
 18 for i in sentence_list:
 19     misspelled_list = sentcheck(i)
 20     for j in misspelled_list:
 21         if j in misspelled_words_dict:
 22             misspelled_words_dict[j] = misspelled_words_dict[j] + 1
 23         else:
 24             misspelled_words_dict[j] = 1
 25 keys = misspelled_words_dict.keys()
 26 for k in misspell_keys:
 27     print k + ' (' + repr(misspelled_words_dict.get(k)) + ')'