Using replace instead of find
<p>I have written the following piece but not able to figure the next part:</p>

<pre><code>if request.guess in game.target:            
  position = game.target.find(request.guess)
  game.correct[position] = request.guess.upper()
</code></pre>

<p>The point here is <code>request.guess</code> is a character input like <code>'a'</code> and <code>game.target</code> is <code>'austin'</code>. So the above code will find the character in the target word and generate an output like <code>a*****</code>. But my code will only work for words that have letters not repeated in them eg: Australia. I know there is a method 'replace' in python but I am not able to figure out how should I incorporate here.</p>

<p>Kindly help!!!!!</p>

<p><code>replace</code> will not help here, since you are not changing the string you are searching.</p>

<p>There are two options here:</p>

<ol>
<li><p>Use <code>str.find</code> repeatedly:</p>

<pre><code>pos = 0
while True:
    pos = game.target.find(request.guess, start=pos)
    if pos == -1: break
    game.correct[pos] = request.guess.upper()
</code></pre></li>
<li><p>Build the string from scratch each time:</p>

<pre><code>game.correct = ''.join(
    letter if letter in request.guesses else '*'
    for letter in game.target
)
</code></pre></li>
</ol>

python python-3.x