Assignment 3 Part 1 (submitted by Peterson on Feb 9, 00:33)

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, 18:06 - Kevin: not sure what the purpose of the function checkword and line 1. probably wouldn't have used dict as a variable name since dict is a type as well. strippunctuation is a good idea but probably would/is more useful if it replaced the " " with "" instead on line 10

Feb 22, 17:59 - Ping (line 29): I didn't know this worked. It's more conventional to say l = dict.keys().

Feb 22, 18:00 - Ping (line 4): I think i know some people who use a spelling-checking algorithm similar to this one.

Please log in if you would like to add comments.

   

  1 execfile("my.py")
  2 
  3 def checkword(word):
  4     return int(random()*1.9)
  5 
  6 def striphelper(inchar):
  7     if inchar.isalpha() or inchar=="'":
  8         return inchar
  9     else:
 10         return " "
 11 
 12 def strippunctuation(instring):
 13     return "".join(map( striphelper, instring ))
 14 
 15 def spellcheckfile(filename):
 16     file = open(filename)
 17     wordlist = strippunctuation(file.read()).split()
 18     mispelled = {}
 19     for w in wordlist:
 20         if not checkword(w):
 21             if mispelled.get(w):
 22                 mispelled[w]=mispelled[w]+1
 23             else:
 24                 mispelled[w]=1
 25     return mispelled
 26 
 27 def spellcheckreport(filename):
 28     dict = spellcheckfile(filename)
 29     l = list(dict)
 30     l.sort()
 31     for i in l:
 32        print i+' ('+str(dict[i])+')'