lists for line in fhandwords line split(print('debug:'wordsif words[ !'fromcontinue print(words[ ]when we run the programa lot of output scrolls off the screen but at the endwe see our debug output and the traceback so we know what happened just before the traceback debug[' -dspam-confidence:'' 'debug[' -dspam-probability:'' 'debug[traceback (most recent call last)file "search py"line in if words[ !'fromcontinue indexerrorlist index out of range each debug line is printing the list of words which we get when we split the line into words when the program failsthe list of words is empty [if we open the file in text editor and look at the fileat that point it looks as followsx-dspam-resultinnocent -dspam-processedsat jan : : -dspam-confidence -dspam-probability detailsthe error occurs when our program encounters blank lineof course there are "zero wordson blank line why didn' we think of that when we were writing the codewhen the code looks for the first word (word[ ]to check to see if it matches "from"we get an "index out of rangeerror this of course is the perfect place to add some guardian code to avoid checking the first word if the first word is not there there are many ways to protect this codewe will choose to check the number of words we have before we look at the first wordfhand open('mbox-short txt'count for line in fhandwords line split(print('debug:'wordsif len(words= continue if words[ !'fromcontinue print(words[ ]first we commented out the debug print statement instead of removing itin case our modification fails and we need to debug again then we added guardian statement that checks to see if we have zero wordsand if sowe use continue to skip to the next line in the file