리스트 중복제거 순서를 유지하기

dup_list = ['1','3','6','5','5','3','4','4','3','2','2','2','1']

# 리스트 원소 순서가 뒤섞여도 상관없는경우

dup_list = list(set(dup_list))

# 순서를 유지하며 중복제거

from collections import OrderedDict
list(OrderedDict.fromkeys(dup_list ))

['1', '3', '6', '5', '4', '2']

출처 : [Python] 리스트 중복 제거 (순서 유지 X, 순서 유지 O)

Leave a Comment