Assignment 3 Part 1 (submitted by Jun on Feb 10, 17:42)

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 13, 15:36 - Calvin: Code is clear and easy to follow. My suggestion is to put wrap this in a few functions so that it's easier to import this module and use it.

Feb 22, 17:51 - Ping (line 23): Don't need the outermost two pairs of parentheses on this line.

Feb 22, 17:53 - Ping (lines 11, 15, 33, 35, 39, 42): These blank lines don't seem necessary to me.

Feb 22, 17:53 - Ping (line 19): Don't need the outermost two pairs of parentheses on this line.

Please log in if you would like to add comments.

   

  1 import speling.py
  2 import string
  3 
  4 if import_entries('dict.txt') != 0
  5     return "Exiting program, no dictionary file"
  6 
  7 myFile = open("doc.txt")
  8 correctionList = []
  9 
 10 for line in myFile:
 11 
 12     # Works at word-level via line-by-line feed of file
 13     x = line.split()
 14     for word in x:
 15 
 16         # Strips off non-alphanumeric & non-apostrophe characters
 17         y = ""
 18         for c in word:
 19             if (c <= 'z') or (c == "'"):
 20                 y = y + c
 21 
 22         # Checks the word against dictionary
 23         if (check_word(string.lower(y)) != []) or (check_word(y) != []):
 24             # good word, skip
 25         else:
 26             # add it to the list of misspelled words
 27             correctionList.extend(y)
 28 
 29 
 30 # At this point, we have a list of misspelled words, with duplications
 31 # thus, we can make a function that will collect the duplicates
 32 def count(myList):
 33 
 34     d = {}
 35     
 36     # Initializes dictionary
 37     for c in myList:
 38         d[c] = 0
 39 
 40     for c in myList:
 41         d[c] = d[c] + 1
 42 
 43     return d
 44 
 45 # Use a dictionary to collect the duplicates.
 46 z = count(correctionList)
 47 
 48 # Make list so we an sort it and print
 49 a = []
 50 for key in z:
 51     a.extend(key + " (" + z[a] + ") \n")
 52 
 53 print a.sort()