title: How to check if a character is in a specific position in a string in Python?
body: <p>I am making an algorithm for hangman that can guess the word quite well, but it's not working exactly as intended. It's supposed to check the specific positions of characters, but it doesn't really work. For example, I'll use the word aardvark. The first letter it guesses correctly is a, and aardvark contains 3 a's, so the algorithm sees this:</p>
  
  <p>aa_ _ _ <em>a</em> _ _</p>
  
  <p>But when I check the possible words, most of them don't look like this, and the algorithm should instantly be able to solve it, as it's the only word that looks like this.</p>
  
  <p>The program has functions to remove words that contain incorrectly guessed letters, and a function to guess the optimal letter. Both of these functions work perfectly.</p>
  
  <p>This is the part of the code that isn't working, and is supposed to check the position of the letters:</p>
  
  <pre><code>def narrowdown(guessedword, possible):
      for i in guessedword:
          if i != "_":
              for j in possible:
                  k = list(j)
                  if k[guessedword.index(i)] != i:
                      possible.remove(j)
  </code></pre>
  
  <p>Here, guessedword is a list version of the letters that the guesser can see, and possible is the list of words that the guessed word can be. The "_" are the blank letters that the guesser can't see.</p>
  
  <p>It repeats this function after every time it has guessed a word.</p>
  
  <p>The problem is that it includes words that definitely aren't eligable. For example, I'll use aardvark again. </p>
  
  <p>When the word looks like this: aa_  _ _ <em>a</em> _ _</p>
  
  <p>And the incorrectly guessed letters are e, i, s and u, it still shows these words:</p>
  
  <p>['aardvark', 'aardwolf', 'abnormal', 'adorably', 'advocacy', 'agaragar', 'agronomy', 'anaconda', 'anaphora', 'approach', 'approval', 'arrogant', 'atombomb']</p>
  
  <p>As I said, aardvark is the only word that fills all those criteria, but the algorithm still takes 3 more guesses to find out which word it is.</p>
  
  <p>Anyone have an idea how to fix this?</p>