I have a while loop that goes over a two-dimensional list, to see if it can find a similar submission for it to be removed.
i=0
while i <= len(my_list):
if my_list[i] == userinput:
del my_list[i]
print("Entry Removed!")
else:
print("This publication does not exist")
i+=1
What I wanted was for the code to print the message "This publication does not exist" if no matches were found. However, what happens right now is that everytime it compares an item, the code prints the sentence.
I understand why this happens but I have no idea how to fix it. What is the best way of addressing this issue?
EDIT: Changed list name from "list" to "my_list". My bad, I didn't actually call it that in the code, I just changed the name when uploading the question for ease of understanding.