title: How can I replace specific characters in python?
body: <p>So I'm trying to make a hangman game. I have a function that turns the word you're trying to guess into underscores. So if your word is house you end up with:  <code>_ _ _ _ _</code></p>
  
  <p>Then I have another function that adds every character from the word into an array. I have a function that lets you make guesses and if the guess is incorrect it takes away a life (I'm using a life system while I figure out how to implement the drawing of the hangman) from you and it adds the wrong letter into an empty array. My program also checks that you don't input anything that's not a letter or that the letters are not repeated.</p>
  
  <p>My only problem is that I can't think of a way of telling the computer that if the letter is in the word it should switch the empty space where the letter would be with your guess. So say if your word is house and you guess the letter h it should return:</p>
  
  <pre><code>h _ _ _ _ 
  </code></pre>
  
  <p>And if I use the replace function it replaces every single underscore with the correct letter. Any suggestions as to what I can do?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import random
  category = [('sports', 1), ('video games', 2), ('movies', 3)]
  sports = ('football', 'baseball', 'basketball')
  video_games = ('counter strike', 'doom', 'wolfenstein')
  movies = ('star wars', 'indiana jones', 'lord of the rings')
  
  
  def pick_category():
      print("For sports type 1, for video games type 2, for movies type 3")
      choice = int(input("Choose a category: "))
      if choice == 1:
          word = random.choice(sports)
      elif choice == 2:
          word = random.choice(video_games)
      elif choice == 3:
          word = random.choice(movies)
      else:
          print("Invalid input")
      return word
  word = pick_category()
  
  def convert_spaces(): #Turns every letter in the word into an empty space
      spaces = word
      for i in range(0, len(word)):
          if ord(word[i]) != 32:
              spaces = spaces.replace(word[i], '_ ')
      print(spaces)
      return spaces
  convert_spaces()
  
  def word_list(): # Appends every letter of the word into an array
      array = []
      for i in range(0, len(word)):
          array.append(word[i])
      print(array)
      return array
  
  def guess():
      array = []
      lives = 9
      while lives != 0:
          n = input("Guess a letter ").lower()
          if ord(n) in range(96, 123):
              if n in array:
                  print("That letter is already in use.")
              elif n not in word and n not in array:
                  array.append(n)
                  lives = lives - 1
          else:
              print("Invalid input, try again")
          convert_spaces()
          print("Used letters: ", array)
          print("Life counter: ", lives)
      return array
  guess()
  </code></pre>