Skip to content

Instantly share code, notes, and snippets.

@adambene
Last active July 1, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adambene/3723992a4b43a29876accbf50908e501 to your computer and use it in GitHub Desktop.
Save adambene/3723992a4b43a29876accbf50908e501 to your computer and use it in GitHub Desktop.
Distinct items in list, naive and verbose implementation
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