Skip to content

Instantly share code, notes, and snippets.

@scresante
Created January 12, 2018 19:14
Show Gist options
  • Save scresante/b4ebfb24415a34ca65eef60d10144265 to your computer and use it in GitHub Desktop.
Save scresante/b4ebfb24415a34ca65eef60d10144265 to your computer and use it in GitHub Desktop.
def runningUniq(anArray, compare=lambda x,y: x==y):
""" non-memory efficient linear deduplicator """
retAr = []
for n, elem in enumerate(anArray):
if n == 0:
last = elem
retAr.append(elem)
continue
if compare(elem, last):
last = elem
continue
else:
last = elem
retAr.append(elem)
return retAr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment