Last active
January 30, 2018 09:34
-
-
Save vikychoi/43558f5e1cb01bd95a6646abd1deb066 to your computer and use it in GitHub Desktop.
List remove duplicates
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 removeduplicates_v1(lst): | |
lst = set(lst) | |
return list(lst) | |
def removeduplicates_v2(lst): | |
new_lst = [] | |
for i in range((len(lst)-1)): | |
if (lst[i] not in new_lst): | |
new_lst.append(lst[i]) | |
return new_lst | |
eg = [1,2,3,4,1,2,3,4] | |
print("eg: ", eg, "\n") | |
print("v1: ", removeduplicates_v1(eg), "\n") | |
print("v2: ", removeduplicates_v2(eg), "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment