Created
February 20, 2019 15:44
-
-
Save rvvvt/55d9a6c1763c675d93d6f5e1cc464997 to your computer and use it in GitHub Desktop.
A quick way to remove duplicates from a Python list. Super easy!
This file contains hidden or 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
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