Assignment 3 Part 1 (submitted by Thanh on Feb 9, 22:47)

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 22, 18:08 - Ping (line 18): There's no need to run a whole new count each time. You're looping through all the items already, so just increment the appropriate dictionary entry each time. (See some of the other students' submitted programs.)

Feb 22, 18:09 - Ping (line 37): Why abbreviate "words" to "wds"? There's no good reason. Just call this list misspelled_words.

Feb 22, 18:10 - Ping (line 40): Again, no need to abbreviate "word" to "wd".

Please log in if you would like to add comments.

   

  1 # Thanh Thai
  2 # cs198-ak
  3 # Text_processing.py
  4 
  5 
  6 
  7 #Part Uno:
  8 
  9 import speling.py
 10 
 11 def count(asequence):
 12     """ Counts the number of time an item appear int he sequence """
 13     dictionary = {}
 14     times = len(asequence)
 15     while times > 0:
 16         last_item = asequence[times-1]
 17         if dictionary.get(last_item) == None:
 18             counter = asequence.count(last_item) 
 19             dictionary[last_item] = counter
 20             times = times - 1
 21         else:
 22             times = times-1
 23     return dictionary
 24 
 25 def print_result(a_dictionary):
 26     """ Print the result of spell_check in an alphabetical order """ 
 27     keylist = a_dictionary.keys()
 28     keylist.sort()
 29     for key in keylist:
 30         print key, '(' , a_dictionary[key], ')'
 31         
 32 
 33 
 34 def spell_check(input.txt):
 35     """ Spellcheck a file """
 36     file = open('input.txt')
 37     misspelled_wds = []
 38     for line in file:
 39         wd_list = speling.parseWords(line)
 40         for each_wd in wd_list:
 41             if speling.checkspelling(each_wd) == None:
 42                 misspelled_wds.append(each_wd)
 43     print_result(count(misspelled_wds))
 44 
 45 
 46 # Part Dos:
 47 
 48 #  I had to assume that the speling.checkspelling(word) will return the word/value if the the word
 49 #  is found in the dictionary, and return None otherwise.