Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 14:10
Show Gist options
  • Select an option

  • Save Averroes/6e643a9ab5f33ce712fd to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/6e643a9ab5f33ce712fd to your computer and use it in GitHub Desktop.
removing duplicates from a sequence while maintaining order
# example.py
#
# Remove duplicate entries from a sequence while keeping order
def dedupe(items):
seen = set()
for item in items:
if item not in seen:
yield item
seen.add(item)
if __name__ == '__main__':
a = [1, 5, 2, 1, 9, 1, 5, 10]
print(a)
print(list(dedupe(a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment