pyassistant

Remove consecutive duplicates from a list

Write a function that takes a list of strings and returns a new list where any consecutive duplicate elements are collapsed to a single occurrence. Only duplicates that are adjacent should be removed; if the same value appears later non-consecutively it should be kept. Examples: - ['a', 'a', 'b', 'b', 'a'] -> ['a', 'b', 'a'] - ['hello', 'hello', 'world'] -> ['hello', 'world'] Implement the function solve(items: list[str]) -> list[str].

Example:

Input:
(['a', 'a', 'b', 'b', 'a'])
Output:
['a', 'b', 'a']

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.