title: Binary Search Python Spell Check
body: <p>I am trying to import a text file (all lower-case words, no punctuation) and compare those words to a dictionary list of words. If a word does not appear in the dictionary list, it is printed as potentially incorrect. If a word does appear in the dictionary list, nothing is done. We are supposed to be using a binary search method here. I think my binary search method is correct, I just don't know where/how to return words that do not appear in the dictionary list and announce them as potentially incorrect.</p>
  
  <p>Thank you!</p>
  
  <p>My input file sentence: the quick red fox jumps over the lzy brn dog</p>
  
  <pre><code>def spellcheck(inputfile):
  
  filebeingchecked=open(inputfile,'r')
  spellcheckfile=open("words.txt",'r')
  
  dictionary=spellcheckfile.read().split()
  checkedwords=filebeingchecked.read().split()
  
  for word in checkedwords:
  
      low = 0
      high=len(dictionary)-1
  
      while low &lt;= high:
  
          mid=(low+high)//2
          item=dictionary[mid]
  
          if word == item:
              return word
  
          elif word &lt; item:
              high=mid-1
  
          else:
              low=mid+1
  
      return word
  
  def main():
  
      print("This program accepts a file as an input file and uses a spell check function to \nidentify any problematic words that are not found in a common dictionary.")
      inputfile=input("Enter the name of the desired .txt file you wish to spellcheck: ")
  
  main()
  </code></pre>