def has_duplicates(lst):
return len(lst) != len(set(lst))
x = [1,2,3,4,5,5]
has_duplicates(x) # True
def checkDuplicate(user):
if len(set(user)) < len(user):
return True
return False
#most efficient solution on Leet code
def containsDuplicate(self,nums)->bool:
d={}
for ele in nums:
if ele not in d:
d[ele] = 1
else:
return True
return False
>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
a = [1,2,3,2,1,5,6,5,5,5]
import collections
print([item for item, count in collections.Counter(a).items() if count > 1])
## [1, 2, 5]