Skip to content

Instantly share code, notes, and snippets.

@ozscosta
Created October 4, 2020 19:40
Show Gist options
  • Save ozscosta/1f23650eea8cffdf52c09442f5e02300 to your computer and use it in GitHub Desktop.
Save ozscosta/1f23650eea8cffdf52c09442f5e02300 to your computer and use it in GitHub Desktop.
remove_adjacent.py
def remove_adjacent(nums):
if not nums:
return []
# return [nums[0]] + [n for c, n in zip(nums[:-1], nums[1:]) if c != n]
lista = [nums[0]]
for current, next_ in zip(nums[:-1], nums[1:]):
if current != next_:
lista.append(next_)
return lista
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment