Skip to content

Instantly share code, notes, and snippets.

@rvvvt
Created February 20, 2019 15:44
Show Gist options
  • Save rvvvt/55d9a6c1763c675d93d6f5e1cc464997 to your computer and use it in GitHub Desktop.
Save rvvvt/55d9a6c1763c675d93d6f5e1cc464997 to your computer and use it in GitHub Desktop.
A quick way to remove duplicates from a Python list. Super easy!
the_list = ['a','a','b','b','c','c']
for each in the_list:
# prints our list with duplicates of course
print(each)
newlist=[ii for n,ii in enumerate(the_list) if ii not in the_list[:n]]
for each in newlist:
# and just like that - newlist has no duplicates!
print(each)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment