Assignment 3 Part 1 (submitted by Nadia on Feb 7, 00:08)

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, 23:43 - Thanh: Your solution2 is kinda short and neat! However, I do find a bug in your code: the return value of sort() is None. So... that will end up causing you an error in the for loop; python will complain that you try to iterate through a non-sequence item. You can fix it by doing word_list.sort() after you have set the tokenized text to word_list.

Please log in if you would like to add comments.

   

  1 import speling
  2 
  3 # Solution 1: (the evil one with large assumptions)
  4 speling.read_dictionary('dict.txt')
  5 speling.check_file('input.txt')
  6 
  7 # Solution 2: (assuming check_file doesn't really do what I want)
  8 
  9 speling.read_dictionary('dict.txt')
 10 word_list = speling.tokenize_text(speling.read_file('input.txt')).sort()
 11 seen = {}
 12 
 13 for word in word_list:
 14     if not speling.check_word(word) and not word in seen:
 15         print word, '('+str(word_list.count(word))+')'
 16         seen[word] = 1