All unique or not
The following method checks whether the given list has duplicate elements. It uses the property of set() which removes duplicate elements from the list.
Python: 3.0    Fatos Morina    03 Jul 2021   0
Login to upvote
1
2
3
4
5
6
7
8
def all_unique(lst):
    return len(lst) == len(set(lst))


x = [1,1,2,2,3,2,3,4,5,6]
y = [1,2,3,4,5]
all_unique(x) # False
all_unique(y) # True
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com