title: Getting index of duplicate letters in a string
body: <pre><code>from graphics import *
  import random 
  
  def hangman(word):
      returnStuff = {'again':0, '1st':1}
  
      alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
                  'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  
      win = GraphWin("Hangman", 800, 550)
      win.setBackground("yellow")
  
      titleText = Text(Point(400,50), 'HANGMAN')
      titleText.setSize(24)
      titleText.setStyle('bold')
      titleText.draw(win)
  
      #Building the hangman base
      base = Line(Point(120,350),Point(230,350))
      base.draw(win)
      stand = Line(Point(175,350),Point(175,150))
      stand.draw(win)
      stand2 = Line(Point(175,150),Point(250,150))
      stand2.draw(win)
      stand3 = Line(Point(250,150),Point(250,180))
      stand3.draw(win)
  
      #drawing the empty lines for the word
      x1 = 150
      x2 = 180
      l = 0
      print(word)
      while l&lt; len(word):
          wordLine = Line(Point(x1, 420),Point(x2,420))
          wordLine.draw(win)
          l+=1
          x1+=40
          x2+=40
  
      guessCounter = 0
      textCheck = 0
      invalidText = Text(Point(600,100), 'You did not enter a valid letter.')
      invalidText.setTextColor('red')
      indexes = []
      while guessCounter &lt; 6:
          #text entry box
          textEntry = Entry(Point(600,180),10)
          textEntry.draw(win)
          guessText = Text(Point(600,150), 'Guess a letter:')
          guessText.draw(win)
          #user has to click this box to confirm the letter
          enterBox = Rectangle(Point(580,200), Point(620,220))
          enterBox.setFill('white')
          enterBox.draw(win)
          clickText = Text(Point(600,210), 'Enter')
          clickText.draw(win)
  
          click = win.getMouse()
          x = click.getX()
          y = click.getY()
  
          if 580 &lt; x &lt; 620 and 200 &lt; y &lt; 220:
              guess = textEntry.getText().lower().strip()
              if guess not in alphabet:
                  if textCheck == 0:
                      invalidText.draw(win)
                      textCheck = 1
  
              else:
                  if textCheck == 1:
                      invalidText.undraw()
                      textCheck = 0
                  for letter in word:
                      if letter == guess:
                          indexes.append(word.index(guess))
                          print(indexes)
  
  
      win.getMouse()
  
      win.close()
  
      return returnStuff 
  
  #list with various words pertaining to nanotechnology
  words = ['nanotechnology', 'science', 'nanometre' , 'strength', 'chemistry',
           'small', 'molecule', 'light' , 'weight', 'technology', 'materials',
           'property', 'physics', 'engineering', 'matter', 'waterloo', 'nanobot',
           'reaction', 'structure', 'cells']
  
  #picks a random word from the list
  word = random.choice(words)
  
  #this variable ensures it opens the game the first time
  initialCall = 1
  #stores the returnValue for the first call
  returnValue = hangman(word)
  
  #sets the initialCall to 0 after first call 
  if returnValue['1st']==1:
      initialCall=0
  
  #Calls the game function again if user wishes
  while initialCall == 1 or returnStuff['again'] == 1:
      returnValue = hangman(word)
  </code></pre>
  
  <p>I am making Hangman in Python graphics. I apologize for the huge block of code, it all works fine, I just thought it must be useful. The part of the code that I'm concerned about is this: </p>
  
  <pre><code>            else:
                  if textCheck == 1:
                      invalidText.undraw()
                      textCheck = 0
                  for letter in word:
                      if letter == guess:
                          indexes.append(word.index(guess))
                          print(indexes)
  </code></pre>
  
  <p>This block of code will be executed when the user's letter guess is in the alphabet, I then run through each letter in the chosen word, and if at any point a letter in the word is the same as the guess letter, I store the index of that letter in a empty list so I can use that to tell the computer where to draw the letters on the empty lines. </p>
  
  <p>It works fine, with the exception of when there is a duplicate letter in the word. For example, engineering has 3 es. Unfortunately, .index() only records the index for when the letter appears the first time, and it disregards the other letters. <strong>What is the work around for this so I can get the indexes of all 3 es in that word, instead of 3 indexes of just the first e.</strong> For testing purposes, I have printed the chosen word and the index list on the console so I can see what's going on and so I don't actually have to guess a letter. </p>