python

중복제거

bumychoi 2024. 7. 4. 20:23
#제거
x=["a",1,"b",2,"a",3,"b",4,5,"b"]
# 방법1 - 순서가 없음
y=list(set(x))
print(y)


#순선유지
from collections import OrderedDict
ex2 =list(OrderedDict.fromkeys(x))
print(f'ex2 결과:{ex2}')

# 방법3- 순서유지
ex3=[]
for i in x:
    if i not in ex3:
        ex3.append(i)
print(ex3)

print("-------------")