Basically, my code removes all duplicates that is next to eachother but for some reason i get error for empty list. I would like to know what code should I add to remove the error when the list is empty?
My code works for list with integers like below for example:
def remove_adjacent(nums):
k2 = [a for a,b in zip(nums, nums[1:]+[not nums[-1]]) if a != b]
return k2
remove_adjacent([1, 2, 2, 2, 3, 3]) == [1, 2, 3]
AS you can see it works but when I have an empty list I get this error:
remove_adjacent([]) == list index out of range
What code should i add to fix this function?