Assignment 3 Part 1 (submitted by Chris on Feb 8, 22:02)

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 12, 11:41 - Ping (line 2): Communication problem: this function name doesn't match the function in Calvin's module [A3P4:Calvin].

Feb 16, 18:28 - Nerissa (line 5): Might want to reconsider some of the variable names; sometimes it's hard to figure out what one variable might stand for.

Feb 16, 18:34 - Nerissa: On the plus side, the code is very concise. =) (Note: In the previous comment I made, I actually meant line 6, not 5.)

Feb 18, 12:41 - Chris (line 6): I guess I should call the variable 'result' instead of 'res'. Or maybe I should call it 'badword_list' but I thought that might be a little too long.

Feb 22, 17:46 - Ping: Very nice-looking code. Please indent 4 spaces instead of 8 spaces, though.

Feb 22, 18:11 - Ping: You need a main program here. Currently, running this script won't do anything.

Please log in if you would like to add comments.

   

  1 def check(fn):
  2         setdictionary("dict.txt")
  3         file = open(fn)
  4         stat = {}
  5         for line in file:
  6                 res = checktext(line)
  7                 for badword in res:
  8                         if stat.get(badword):
  9                                 stat[badword] = stat[badword] + 1
 10                         else:
 11                                 stat[badword] = 1
 12         # put everything into array for sorting
 13         arr = []
 14         for word in stat:
 15                 arr.append(word + str(" (") + str(stat[word]) + str(")"))
 16 
 17         arr.sort()
 18         for word in arr:
 19                 print word