Skip to content

Instantly share code, notes, and snippets.

@Tevinthuku
Created January 29, 2019 17:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tevinthuku/003f67d2ba31b46655288dbd9a244878 to your computer and use it in GitHub Desktop.
Save Tevinthuku/003f67d2ba31b46655288dbd9a244878 to your computer and use it in GitHub Desktop.
Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.
def unique_in_order(iterable):
listofargs = [x for x in (list(iterable))]
uniqueList = []
prevItem = None
for item in listofargs:
if item == prevItem:
prevItem = item
continue
else:
uniqueList.append(item)
prevItem = item
return uniqueList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment