Created
December 7, 2017 11:04
-
-
Save SZ-Edward/f6b04c29c151d925e9b83435e82fdc80 to your computer and use it in GitHub Desktop.
Remove subsequent duplicates from list with keeping order.
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 remove_duplicates_of_list(lst): | |
if len(lst) < 2: | |
return lst | |
d = {} | |
for i in xrange(len(lst)): | |
if lst[i] in d.values(): | |
continue | |
d.update({i: lst[i]}) | |
return [lst[key] for key in sorted(d.keys())] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello I have an improvement
lst = list(set(lst))
does the job, is built-in and is way faster.Try with a 500000 elements list :
:-)