Created
January 29, 2019 17:53
-
-
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.
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 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