python - List 중복 제거 방법


python - List 중복 제거 방법

Python List 중복 제거 방법은 다음과 같다. 입력 my_list = [1, 2, 3, 3, 4, 4, 5] set방법 result = list(set(my_list)) 2. 새로운 리스트를 생성하면서 중복 제거 result = [] for i in my_list: if i not in result: result.append(i) 3. collection 모듈의 Counter (Python 3.1부터 지원) from collections import Counter counter = Counter(my_list) result = [key for key, value in counter.items() if True] 4. OrdereDict 객체 활용 (Python 2.7부터 지원) from collections import OrderedDict result = list(OrderedDict.fromkeys(my_list)) 아래는 코드 예시이다. 위의 방식 모두 적용 가능하다. ...


#Counter #List #List중복 #List중복제거 #OrdereDict #python #set #중복 #파이선

원문링크 : python - List 중복 제거 방법