I'm trying to build a function that when passed a letter and a word as an argument, returns a list of strings with this format: '' for each letter with exception of the given letter. So when passed "house" and "o" should return ["", "o","","","_"] .
The problem is when the letter appears more than one time.
def char_positioner(word, guessAttempt):
listedWordBlanks = list(len(word) * '_')
i = word.index(guessAttempt)
if guessAttempt in word:
listedWordBlanks[i] = word[i]
return listedWordBlanks
This is my second attempt but still getting the same result:
word = ['rotten']
wordSpaces = len(word[0]) * '_'
listWordSpaces = list(wordSpaces)
def testPositioner(char):
for space in listWordSpaces:
if char in word[0]:
for letter in word[0]:
listWordSpaces[word[0].index(char)] = char
return listWordSpaces
testPositioner('t')
Expected result: ['_','_','t','t','_','_',]
**Got:**['_','_','t','_','_','_']