You have two errors in your code.
- If the last element is 13, then the first element with not be added because
lst[0-1] == 13
because of Python's index wrap around. - As stated in the comments and in the other answer, you should be using
and
, instead ofor
. This is because of De Morgan's laws.
Then, the resulting code is
sum([lst[i] for i in range(len(lst)) if not lst[i] == 13 and not(i > 0 and lst[i-1] == 13)])