I'm new to programming in general, started on boxing day. I'm trying to
learn python.
The list remove method only removes the first instance of the value found.
In the code below I attempted to remove all the instances.
Are there better ways of accomplishing this? Is this efficient? Any and all feedback is wanted.
wordlist = ["dog", "cat", "mouse", "giraffe", "cat"]
remove_queue = []
userinput = input("remove: ")
for i in range(len(wordlist)):
if wordlist[i] == userinput:
remove_queue.append(i)
""""reversed the list, so when deleting a value, the position of the other
values don't change"""
remove_queue.sort(reverse=True)
for i in range(len(remove_queue)):
"""uses the remove_queue list to find the position of value that needs to be
removed, and removes it. """
del wordlist[remove_queue[i]]
print(wordlist)