pyassistant

Remove Consecutive Duplicates from a List

Given a list of integers, return a new list where any consecutive duplicate elements are collapsed to a single occurrence. Only duplicates that appear next to each other should be removed; non-consecutive repeats should be kept. Examples: - [1, 1, 2, 2, 3] -> [1, 2, 3] - [1, 2, 1, 1] -> [1, 2, 1] Write a function that performs this transformation.

Example:

Input:
([1, 1, 2, 2, 3, 3, 3],)
Output:
[1, 2, 3]

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.