I answered a similar question a while back. Hopefully it’s helpful, if not, sorry.
You are correct, index()
& find()
return the first occurrence only. If you need to collect all the occurrences of a particular item in an iterable, a for loop
can easily do that. Even better, Python allows for list comprehensions to condense and speed up these kinds of things.
# Just demonstrating another Python method for random choice
from random import choice
word_list = ['elephant', 'giraffe,', 'snake', 'tiger', 'monkey', 'bird', 'leopard', 'crocodile', 'buffalo', 'mouse', 'wolf', 'pig', 'chicken', 'cheetah', 'hyena', 'shark', 'dolphin', 'lizard', 'whale', 'panda', 'gorilla']
word_choice = choice(word_list) # Picks a random item from word_list
word_board = ['_' for _ in word_choice] # warm-up
letter_guess = input("Enter a letter. ")
# generates a list of indices for characters matching letter_guess
# list will be empty if no matching characters are found in word_choice
indices_of_guess = [idx for idx, letter in enumerate(word_choice) if letter == letter_guess]