I'm trying to solve a little puzzle, where I need to delete the number 13, and the number after that in a list (its an exercise on CodingBat).
This is my code:
n = [1, 2, 3, 13, 5, 13]
for i in n:
if i == 13:
n.remove(i) and n.remove(n.index(i+1))
print n
Desired output: [1, 2, 3]
However, my incorrect output is: [1, 2, 3, 5] #the item after 13 (i.e. 5) did not get deleted
I thought that this n.remove(n.index(i+1))
would remove the item after 13, but it doesn't.