collapse_consecutive(items) that returns a new list where every run of consecutive equal values is collapsed to a single value (unlike full dedup, non-adjacent repeats are kept separately).items = [1, 1, 2, 2, 2, 1, 3, 3]
[1, 2, 1, 3]
Each run of identical neighbors collapses to one; the 1 reappears after the 2s since it is a new run.
Walk through the list and only append a value if it differs from the last value appended.