All unique

PHOTO EMBED

Tue Mar 31 2020 11:40:31 GMT+0000 (Coordinated Universal Time)

Saved by @amnasky #python #python #function #return #allunique

#define function
defall_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
content_copyCOPY

The above method checks whether the given list has duplicate elements. It uses the property of set() which removes duplicate elements from the list.

https://towardsdatascience.com/30-helpful-python-snippets-that-you-can-learn-in-30-seconds-or-less-69bb49204172