title: Duplicate letters in wordle
body: <p>For a school project I have to create a wordle in Python. The program I created compares the letters of the target word and the guessed word. An example: the target word is  &quot;compulsory&quot; and the guessed word is &quot;submission&quot;. The output should be &quot;-O-O--X-O-&quot;.</p>
  <p>&quot;X&quot; meaning the letter in the guessed word is also in the target word and is at the same spot.
  &quot;O&quot; meaning the letter in the guessed word is also in the target word but isn't at the same spot.
  &quot;-&quot; means that it's the wrong letter.</p>
  <p>But I can't seem to find a way to cope with duplicate letters. For example, if the target word is &quot;teethe&quot; and the guessed word is &quot;health&quot; it should give me the output: &quot;OX--O-&quot;. Though my program returns the output: &quot;OX--OO&quot;.</p>
  <p>My code:</p>
  <pre><code>    def compare(guess, target):
          output = &quot;&quot;
          for i in range(target.__len__()):
              if guess[i] == target[i]:
                  output = output + &quot;X&quot;
              elif guess[i] in target:
                   output = output + &quot;O&quot;
              else:
                  output = output + &quot;-&quot;
          return output
      print(compare(&quot;health&quot;, &quot;teethe&quot;)) 
  
  </code></pre>
  <p>I hope I provided enough information for you to understand my question/problem.</p>
  <p>Thank you in advance for your help!</p>