duplicated in list python code example
Example 1: count the duplicates in a list in python
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)
Example 2: python duplicate list elements
def duplicate_list_elements(_list : list):
duplicated_list = []
for element in _list:
duplicated_list.append(element)
duplicated_list.append(element)
return duplicated_list