Python check for duplicate list elements
Check for duplicate elements in a Python list.
def unique_elements(lst):
return len(lst) == len(set(lst))
x = [1,1,2,2,3,4]
y = [1,2,3,4]
unique_elements(x) # False
unique_elements(y) # True
Check for duplicate elements in a Python list.
def unique_elements(lst):
return len(lst) == len(set(lst))
x = [1,1,2,2,3,4]
y = [1,2,3,4]
unique_elements(x) # False
unique_elements(y) # True