I am trying to make something where the user clicks a button that corresponds to a letter of a word. then it will go through a big list of words and delete anything where the letter they clicked doesnt correspond with a letter in a word in the list. For some reason though, it seems like its just deleting random stuff and not actually deleting the words I want it to. For example if I give it the word "crane" and click the button that corresponds to the letter "r" then I want it to go through and delete every word in the list that doesnt have an "r" in the second spot
if 125 <= x <= 275 and 190 <= y <= 240:
print("clicked done")
runs = 0
if numclicks1 % 2 == 0:
for word in wordList:
if word[0] != letterArray[0]:
wordList.remove(word)
runs += 1
if numclicks2 % 2 == 0:
for word in wordList:
if word[1] != letterArray[1]:
wordList.remove(word)
runs += 1
if numclicks3 % 2 == 0:
for word in wordList:
if word[2] != letterArray[2]:
wordList.remove(word)
if numclicks4 % 2 == 0:
for word in wordList:
if word[3] != letterArray[3]:
wordList.remove(word)
if numclicks5 % 2 == 0:
for word in wordList:
if word[4] != letterArray[4]:
wordList.remove(word)
'''print the length of wordList'''
print(len(wordList))
findYellow(letterArray, wordList)
to break it down a little further, if you look at each section, the first if statemnet just asks if the button was clicked or not (99.9% sure that works). the for loop then goes through each index (word) in the array wordList, and the second if statement checks if the letter at the given index isnt equal to the letter at the given index in the current word that the for loop is on.