习题9.1 编写一个程序,读取words.txt文件中的单词,将他们作为键存储在字典中,此时不需要关心键对应的值,然后,使用in操作符快速判断某一字符是否存在于字典中。
fname = raw_input('Please enter file name:')
fhand = open(fname)
words = dict()
for line in fhand:
wordlist = line.split()
for word in wordlist:
if word not in words:
words[word] = 1
else:
words[word] = words[word] + 1
print words
#print 'writing' in words
if 'what' in words:
print '\'what\' is in dictionary'
else:
print '\'what\' is not in dictionary'