Assignment 3 Part 1 (submitted by Scott on Feb 12, 20:13)

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, 09:32 - Jun (line 4): It's cool how the design is very simple and can handle the exception of a file not found.

Feb 17, 09:33 - Jun (line 11): Using a dictionary is a good way to collect pairs of information, like the word and the number of repititions.

Feb 17, 09:34 - Jun (line 14): However, it seems like the program does not account for the punctuations.

Feb 22, 18:10 - Ping: Very clean. Well done.

Please log in if you would like to add comments.

   

  1 import speling
  2   '''assume that module imports dictionary file'''
  3 
  4 try:
  5     text = open("input.txt", r) #assume imput.txt is in same directory
  6 except:
  7     text = raw_input("Enter text to be checked for spelling errors:")
  8 
  9 words_in_text = text.split()
 10 
 11 mispelled = {}
 12 
 13 for word in words_in_text:
 14     if speling.check(word) == 0:
 15         mispelled[word] = mispelled.get(word, 0) +1
 16     else: break
 17 keys = mispelled.keys()
 18 keys = keys.sort()
 19 
 20 for key in keys:
 21     print key + ' (' + mispelled[key] + ')'