Assignment 3 Part 4 (submitted by Jacob on Feb 10, 16:04)

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   Scott   Thanh   Varun

Download this file.

COMMENTS

Feb 12, 23:15 - Jacob: Please change this to use a dictionary. I was really lazy. :(

Feb 12, 23:15 - Jacob (line 1): ie, set words={}

Feb 13, 21:22 - Nadia: A list works. If you really want, I can change it. Your code is easy to read and seems to work to boot. Nice. The "holder" looping scheme is a bit odd... and I'm not sure why you have both isindict and lookup. Where did your docstrings go?

Feb 17, 18:45 - Jacob: sorry about the docstrings. I hope the code is clear as to what they do

Feb 17, 18:45 - Jacob: isindict is what my partner used, so I implemented it for testing purposes

Feb 17, 18:46 - Jacob: my loop looks like that b/c I didn't feel like doing while 1 ... break, and I needed to initialized word.

Please log in if you would like to add comments.

   

  1 words = []
  2 
  3 def setdict(dictionary):
  4     dict = open(dictionary)
  5     word = "holder"
  6     while word:
  7         word = dict.readline().strip()
  8         words.append(word)
  9     dict.close()
 10 
 11 def isindict(word):
 12     return lookup(word)
 13 
 14 def lookup(word):
 15     if word in words:
 16        return 1
 17     elif word.lower() in words:
 18        return 1
 19     else:
 20        return 0
 21 
 22 setdict("dict.txt")