When the List Changes Underneath You

We already have <code>pop(index)</code>, which removes the item at a position we name. Often we do not know the position, only the value. For that there…

Removing by value
We already have pop(index), which removes the item at a position we name. Often we do not know the position, only the value. For that there is remove(value).
Asking whether a list holds a value
So it is worth being able to ask first. Written between a value and a list, in is a QUESTION, and its answer is True or False.
That is the same word a for-each header uses, doing a completely different job. In a header, in means walk this list one item at a time. On its own, it means is this value somewhere inside, yes or no. Which job it is doing depends on where it is written.
Reading a list is safe. Resizing one while you read it is not.
Every loop so far in this unit has left the list the same length as it found it. A for-each loop keeps a hidden position counter, and it moves that counter forward after each pass. If the list gets shorter in the middle of the loop, every item behind the removal slides one place to the left, and the counter moves forward anyway. It lands past an item that was never looked at.
One 3 survives. When the first 3 is removed, the second slides from position 2 to position 1, but the counter has already moved on to position 2, which now holds the 8. The surviving 3 is never visited.
Comparing neighbours
Some questions are not about single items but about PAIRS of items standing next to each other: is this list in order, where is the biggest jump. For those we need two items at once, so we index twice: vals[i] and vals[i + 1].