Algorithm/Python
[Python] set 함수 (중복제거)
채소기
2023. 9. 27. 02:28
#list에 중복된 값이 있으면 true, 없으면 false 반환
def has_duplicates(1st):
return len(1st) != len(set(1st))
x = [1,2,3,4]
y = [3,3,3,3]
has_duplicates(x) # false
has_duplicates(y) # true
코딩테스트 문제에서 중복된 요소가 있는지 확인할 때 요긴하게 사용할 수 있다.