filter double letter words from a list

Viewed 88

I have made a piece of code that filters a list, using a set of inputs from the user. Like wordle, if the letter is in the right place it is green, if it is in the wrong place you select yellow and if the letter is not in the word you select grey. however there is a small issue where if you have a word with two letter in it for example 'drill' and I say the first L is yellow but the second L is grey the code gets rid of all words with L, when I only want it to get rid of the double letter Ls.

    count = 0
    while count < 5:
        count = count + 1
        result = input('''what was the result of your letter? 
please write the colour
- green = g
- yellow = y
- grey = gr
answer: ''')
        if result.lower() == 'gr':
                letter11 = input('what is the letter: ')
                wlist = [word for word in wlist if not any(map(lambda x: x in word, letter11))]
        if result.lower() == 'g':
                letter12 = input('what was the letter: ')
                position11 = int(input('what was the position of the letter: '))
                wlist = [x for x in wlist if x[position11 - 1] == letter12]
        if result.lower() == 'y':
                letter13 = input('what was the letter: ')
                position13 = int(input('what was the position of the letter : '))
                wlist = [word for word in wlist if letter13 in word and word[position13-1] != letter13]
print(wlist,'choose any one of these words')
0 Answers
Related