pyassistant

Remove Consecutive Duplicates from a List

Write a function that takes a list of integers and returns a new list with consecutive duplicate values removed. Only duplicates that are adjacent should be collapsed; non-consecutive repeats should be kept. Examples: - [1, 1, 2, 2, 3] -> [1, 2, 3] - [1, 2, 1] -> [1, 2, 1] Implement the function solve(lst) that returns the filtered list.

Example:

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

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.