Created
December 5, 2019 01:15
-
-
Save FerdinaKusumah/b85cf132a6a3f041bd82121579824d8f to your computer and use it in GitHub Desktop.
Remove Duplicate List Or Dict
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
from collections import OrderedDict | |
"""Remove duplicate in list""" | |
a = [1, 1, 3, 4, 6, 7, 4, 6, 2, 1] | |
remove_duplicate_list = list(set(a)) | |
print(remove_duplicate_list) | |
# [1, 2, 3, 4, 6, 7] | |
"""Remove duplicate in dict and keep order""" | |
b = ["apple", "banana", "grape", "banana", "watermelon"] | |
remove_dup_keep_order = OrderedDict.fromkeys(b).keys() | |
print(remove_dup_keep_order) | |
# odict_keys(['apple', 'banana', 'grape', 'watermelon']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment