Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created July 28, 2020 13:59
Show Gist options
  • Save FerdinaKusumah/bf6201426c9e6621039ab55637f804bc to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/bf6201426c9e6621039ab55637f804bc to your computer and use it in GitHub Desktop.
[Python] remove duplicate
from collections import OrderedDict
"""remove duplicate"""
num = [9, 9, 8, 7, 1, 3, 5, 3, 4, 7, 8, 2]
"""if order is not important"""
unique_sort_num = list(set(num))
# [1, 2, 3, 4, 5, 7, 8, 9]
"""if order is important"""
unique_num = list(OrderedDict.fromkeys(num).keys())
# [9, 8, 7, 1, 3, 5, 4, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment