''' Purpose: spell check a line of input ''' # import get module for url supoprt import url # define link for spelling dictionary WORDS_FOLDER_URL = "http://www.cs.virginia.edu/~cs1112/datasets/words/" SPELLING_LIST_URL = WORDS_FOLDER_URL + "most-common" # get the spelling list as a list of words text = url.get_contents( SPELLING_LIST_URL ) spellings = text.split() # Get a list of correctly spelled words from # the web file - we do this once! It's just a huge list of correctly # spelled words. # print( spellings ) # get the user text as a list of words reply = input( "Enter text: " ) reply = reply.lower() words = reply.split() # Every word in spellings list is lowercase. # We want to check if each word in our text (user input) # in the words list is in spellings. Print it out if it's not in there! # consider the words one by one -- determine whether current word is misspelled. for word in words: if (word not in spellings): print(word) else: pass # We need to find out if word is misspelled # Remember some commonly used test expression things include # >=, <=, ==, in, not in, and, or, etc. Could one of these help? # if ( a in b ) - checks if a is in the sequence b (can be string or list) # Alternate Way: # if ( word in spellings ): # pass # else: # if word not in spellings # print( word ) # all done