Created
October 4, 2020 19:40
-
-
Save ozscosta/1f23650eea8cffdf52c09442f5e02300 to your computer and use it in GitHub Desktop.
remove_adjacent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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