Hopefully the way I worded the question makes sense. I'm creating a simple version of the game "Hangman." I want the user to be able to see where a correct guess is positioned in the word. I figured I can accomplish this by using two lists. List A contains the word the user is trying to guess. List B contains correct guesses and their position in the word. I know how to find the position of the letters in list A, but I can't seem to figure out how to place the correct guesses at their corresponding indices in list B.
I found the indices of list A using
print([i for i, x in enumerate(word) if x == answer])
Now the problem is that I can't figure out how to use their position to correctly insert correct guesses into their corresponding indices. Words with more than one instance of a given letter make this kinda hard for me.
def get_word():
try:
get_answer = list(input('Please type a word: '))
except TypeError:
print('Words only please!')
return get_answer
def check_guess(word):
print('Welcome to hangman!')
missing_char = '_'
progress_list = []
guess_list = []
print('Your word is', +len(word), 'characters long. You will get',+len(word)+3, 'guesses. Good luck!\n')
guesses = len(word) + 3
for j in word:
progress_list.append(missing_char)
for i in range(guesses):
while guesses > 0:
answer = input('Enter a letter: ')
print()
guesses -= 1
if answer in word:
progress_list.insert(0, answer)
guess_list.append(answer)
print("Correct! The letter '", answer, "' appears", word.count(answer),"time(s)!")
print()
print('Here are all of your guesses so far: ',guess_list)
print()
print('Here is what is left', progress_list)
print()
print('You have', +guesses, 'guesses left! ')
print()
else:
print('Sorry, that letter does not appear in the word')
print()
guess_list.append(answer)
print('Here are all of your guesses so far: ',guess_list)
print()
print('Here is what is left', progress_list)
print()
print('You have', +guesses, 'guesses left! ')
print()
check_guess(get_word())