xxxxxxxxxx
names = ['name1', 'name2', 'name3', 'name2']
set([name for name in names if names.count(name) > 1])
xxxxxxxxxx
l=[1,2,3,4,5,2,3,4,7,9,5]
l1=[]
for i in l:
if i not in l1:
l1.append(i)
else:
print(i,end=' ')
xxxxxxxxxx
>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
xxxxxxxxxx
from collections import Counter
def get_duplicates(array):
c = Counter(array)
return [k for k in c if c[k] > 1]
xxxxxxxxxx
def find_duplicates(input_list):
seen = set()
duplicates = set()
for x in input_list:
if x in seen:
duplicates.add(x)
seen.add(x)
return duplicates
# Example usage
my_list = [1, 2, 3, 2, 1, 5, 6, 5, 5, 7]
print(find_duplicates(my_list)) # Output will be {1, 2, 5}
xxxxxxxxxx
def findDuplicates(items):
""" This function returns dict of duplicates items in Iterable
and how much times it gets repeated in key value pair"""
result = {}
item = sorted(items)
for i in item:
if item.count(i) > 1:
result.update({i: items.count(i)})
return result
print(findDuplicates([1,2,3,4,3,4,2,7,4,7,8]))
# output will be {2: 2, 3: 2, 4: 3, 7: 2}
xxxxxxxxxx
How to Find Out the Duplicated Values Present In a List:
some_list=['a','b','c','b','d','m','n','n']
my_list=sorted(some_list)
duplicates=[]
for i in my_list:
if my_list.count(i)>1:
if i not in duplicates:
duplicates.append(i)
print(duplicates)
xxxxxxxxxx
thelist = [1, 2, 3, 4, 4, 5, 5, 6, 1]
def dup(x):
duplicate = []
unique = []
for i in x:
if i in unique:
duplicate.append(i)
else:
unique.append(i)
print("Duplicate values: ", duplicate)
print("Unique Values: ", unique)
dup(thelist)
xxxxxxxxxx
thelist = [1, 2, 3, 4, 4, 5, 5, 6, 1]
def dup(x):
duplicate = []
unique = []
for i in x:
if i in unique:
duplicate.append(i)
else:
unique.append(i)
print("Duplicate values: ", duplicate)
print("Unique Values: ", unique)
dup(thelist)
xxxxxxxxxx
arr = [1,3,6,2,1,6]
for i in range(0, len(arr)):
for j in range(i+1, len(arr)):
if(arr[i] == arr[j]):
print(arr[j]) #output = 1 6