Last active
July 1, 2020 19:04
-
-
Save adambene/3723992a4b43a29876accbf50908e501 to your computer and use it in GitHub Desktop.
Distinct items in list, naive and verbose implementation
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 distinct_naive_verbose(items): | |
""" | |
This naive and verbose implementation returns distinct elements of a list. | |
""" | |
results = list() | |
# iterate through all items | |
for item in items: | |
member = False | |
# linear search for the actual item in results | |
for result in results: | |
if item == result: | |
member = True | |
break | |
# if we didn't find the item in results it is unique and we append to the results | |
if not member: | |
results.append(item) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment