In brief, the reason you are getting the strange result is because you are iterating over your list while deleting its content.
Explanation
First time your loop runs, the internal iterator is pointing at the first element of the loop, which is [1,1,1]
.
Since this element fails the initial condition, it is removed. When it is removed, the list internally will shift the next element ([3,0,0]
) to the left to now occupy the position of the element that was removed.
Now the for-loop will attempt to go to the next element, but it now thinks that it has reached the end of the list, so it stops, and you are left with [3,0,0]
.
Solution
Instead of modifying the original list, the more pythonic solution is to create a new list consisting of just the elements you wanted, while ignoring the ones you don't want, and this is often accomplished by using list-comprehension.
a_list = [[1, 1, 1], [3, 0, 0]]
filtered_a_list = [elem for elem in a_list if sum(elem) != 3]
You can also do it without list-comprehension:
a_list = [[1, 1, 1], [3, 0, 0]]
filtered_a_list = []
for elem in a_list:
if sum(elem) != 3:
filtered_a_list.append(elem)