# # Torbert, 8.20.2008 # # Spell-checker, Version 1.1 # # Input: dictionary of six-letter words and a string entered by the user # Process: determine if the user's string is a word in the dictionary # Output: indicate YES or NO # infile=open('words.txt') wlist=infile.read().split('\n')[:-1] infile.close() ustr=raw_input('String: ') found=False i = 0 while i < len(wlist) and not found: if wlist[i]==ustr: found=True else: i += 1 if found: print 'Yes, %s is a word.' % (ustr) # mods a string by a tuple else: print 'No, %s is not a word.' % (ustr) # # Notes # ----- # This version uses a boolean variable and a for-loop to determine list # membership. The Python for-loop is like Java's iterator for-loop and # there is no traditional C-style for-loop in Python. #