In my program, the user inputs a secret word that another person is to guess (hangman). The letters are then put into a list. I am trying to make a loop that checks if there are several equal letters in the list, and remove them if there is. This I have managed. The problem is that this loop also removes other characters that are not ment to be removed.
word = []
for i in range(int(len(secret_word)) - 1):
if word[l] == word[q]:
word.pop(l)
q += 1
if q > int(len(word)):
break
else:
l +=1
Using the word "secret" and then printing the list, the output I get is
['s', 'c', 'e', 't']
It has removed the e, but unfortunately the r is also removed. Also, this loop doesn't remove a third equal letter. Using "secretive" the output is
['s', 'c', 'e', 'i', 'e']
Here, removing one of the e's, but also r, t and v