0 out of 464 challenges solved
Write a Python function `consecutive_duplicates` that removes consecutive duplicate elements from a given list. The function should return a new list where only the first occurrence of each consecutive duplicate is retained. #### Function Signature ```python [main.nopy] def consecutive_duplicates(nums: list) -> list: pass ``` #### Example Usage ```python [main.nopy] print(consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])) # Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4] print(consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd', 'a', 'a'])) # Output: ['a', 'b', 'c', 'd', 'a'] ``` #### Constraints - The input list can contain any hashable elements (e.g., integers, strings, etc.). - The function should preserve the order of the elements in the input list.
from itertools import groupby def consecutive_duplicates(nums: list) -> list: """ Remove consecutive duplicate elements from the list. Args: nums (list): The input list containing elements. Returns: list: A new list with consecutive duplicates removed. """ # Placeholder for the solution pass