title: Palindrome Index - Python
body: <p>Needing help with a program that is intended to return the index of a key to be deleted for a word that is one key off a palindrome (reads same front to back with whitespace removed). If already a palindrome or two + keys off it just returns none. The program works fine for most except for a word like 'reefer'. Instead of returning the index of the first 'e' to be deleted, it is returning the index of 'f'. This is because the code that checks if the letter after in the reverse direction is the same in the forward direction finds that there is an 'e' in both directions and therefore the 'f' must be wrong. 
  There must be a better way of doing this, or can anyone think of a way to fix this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>def near_palindrome(word):    
      string = list(word.replace(' ', ''))
      is_pal = is_palindrome(string)
      if is_pal == False:
          result = []
          for char in string:
              rev_index = len(string) - string.index(char) - 1       
              if string[string.index(char)] != string[rev_index]:
                  if string[string.index(char) + 1] == string[rev_index]:
                      result.append(string.pop(string.index(char)))                
                  elif string[string.index(char)] == string[rev_index - 1]:
                      result.append(string.pop(rev_index))                    
  
          if len(result) == 1 and is_palindrome(string) == True:
              for s in word:
                  if s == result[0]:
                      return word.index(s)
  
  def is_palindrome(word):
      if word == word[::-1]:
          return True
      else:
          return False</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>                return word.index(s)
  </code></pre>
  
  <p>def is_palindrome(word):
      if word == word[::-1]:
          return True
      else:
          return False</p>