Assignment 3 Part 4 (submitted by Derek on Feb 10, 18:39)

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 23, 16:12 - Ping (line 16): Don't leave a space between the function name and the opening parenthesis here.

Feb 23, 16:12 - Ping (line 17): Add a space after each comma here.

Feb 23, 16:12 - Ping (line 5): Yes, this is right. Dictionaries use hashes of their keys, which enable faster lookup.

Please log in if you would like to add comments.

   

  1 #!/usr/bin/python
  2 
  3 
  4 #using a Dictionary even though don't need the lookup pair because
  5 #I'm guessing that its internal searching will be faster than using a list
  6 
  7 dict = { }
  8 
  9 #initialize dictionary
 10 
 11 dictf = open('dict.txt')
 12 for word in dictf:
 13     word = word.strip()
 14     dict[word]='1'
 15 
 16 def isindict (word):
 17     return dict.get(word,0) or dict.get(word.lower(),0)